From 83ebb999c8488d88d8fdb7e0d8f3f4e976e695ff Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 28 Aug 2015 03:23:15 -0500 Subject: [PATCH] transforms.Inferencer: improve attribute unification diagnostic. --- artiq/compiler/embedding.py | 1 + artiq/compiler/transforms/inferencer.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/artiq/compiler/embedding.py b/artiq/compiler/embedding.py index 0b903dbe0..ed9ec1ad4 100644 --- a/artiq/compiler/embedding.py +++ b/artiq/compiler/embedding.py @@ -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 diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index aa726e98f..852617c5e 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -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.