forked from M-Labs/artiq
1
0
Fork 0

transforms.Inferencer: improve attribute unification diagnostic.

This commit is contained in:
whitequark 2015-08-28 03:23:15 -05:00
parent 98bb570aec
commit 83ebb999c8
2 changed files with 15 additions and 1 deletions

View File

@ -10,6 +10,7 @@ from collections import OrderedDict, defaultdict
from pythonparser import ast, algorithm, source, diagnostic, parse_buffer from pythonparser import ast, algorithm, source, diagnostic, parse_buffer
from ..language import core as language_core
from . import types, builtins, asttyped, prelude from . import types, builtins, asttyped, prelude
from .transforms import ASTTypedRewriter, Inferencer, IntMonomorphizer from .transforms import ASTTypedRewriter, Inferencer, IntMonomorphizer

View File

@ -91,9 +91,22 @@ class Inferencer(algorithm.Visitor):
object_type = node.value.type.find() object_type = node.value.type.find()
if not types.is_var(object_type): if not types.is_var(object_type):
if node.attr in object_type.attributes: if node.attr in object_type.attributes:
def makenotes(printer, typea, typeb, loca, locb):
return [
diagnostic.Diagnostic("note",
"expression of type {typea}",
{"typea": printer.name(typea)},
loca),
diagnostic.Diagnostic("note",
"expression of type {typeb}",
{"typeb": printer.name(object_type)},
node.value.loc)
]
# Assumes no free type variables in .attributes. # Assumes no free type variables in .attributes.
self._unify(node.type, object_type.attributes[node.attr], self._unify(node.type, object_type.attributes[node.attr],
node.loc, None) node.loc, None,
makenotes=makenotes, when=" for attribute '{}'".format(node.attr))
elif types.is_instance(object_type) and \ elif types.is_instance(object_type) and \
node.attr in object_type.constructor.attributes: node.attr in object_type.constructor.attributes:
# Assumes no free type variables in .attributes. # Assumes no free type variables in .attributes.