forked from M-Labs/artiq
transforms.Inferencer: improve attribute unification diagnostic.
This commit is contained in:
parent
98bb570aec
commit
83ebb999c8
|
@ -10,6 +10,7 @@ from collections import OrderedDict, defaultdict
|
|||
|
||||
from pythonparser import ast, algorithm, source, diagnostic, parse_buffer
|
||||
|
||||
from ..language import core as language_core
|
||||
from . import types, builtins, asttyped, prelude
|
||||
from .transforms import ASTTypedRewriter, Inferencer, IntMonomorphizer
|
||||
|
||||
|
|
|
@ -91,9 +91,22 @@ class Inferencer(algorithm.Visitor):
|
|||
object_type = node.value.type.find()
|
||||
if not types.is_var(object_type):
|
||||
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.
|
||||
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 \
|
||||
node.attr in object_type.constructor.attributes:
|
||||
# Assumes no free type variables in .attributes.
|
||||
|
|
Loading…
Reference in New Issue