# HG changeset patch # User Paul Boddie # Date 1398978251 -7200 # Node ID 8dd72f06cb4a8d7f65b784fe9c5bcbfb45bca3f9 # Parent 4c2ac7cb47f72169bddfe0a0d61108f3e2b99688 Prevent guard generation when untyped instances are indicated for names. diff -r 4c2ac7cb47f7 -r 8dd72f06cb4a micropython/deduce.py --- a/micropython/deduce.py Thu May 01 23:03:06 2014 +0200 +++ b/micropython/deduce.py Thu May 01 23:04:11 2014 +0200 @@ -22,7 +22,7 @@ from micropython.stdcompiler import compiler from compiler.ast import * -from micropython.basicdata import Const, Constant, TypedInstance +from micropython.basicdata import Constant, TypedInstance from micropython.common import ASTVisitor, used_by_unit from micropython.data import * from micropython.errors import * @@ -568,15 +568,32 @@ types = self.get_targets_from_type_names(node._attrtypes.get(name)) value = node._values.get(name) + if isinstance(value, BaseAttr): + values = value.get_values() + else: + values = [value] + + # Obtain values with identifiable types. + + typed_values = set() + + for v in values: + if isinstance(v, Instance): + if not isinstance(v, TypedInstance): + return + typed_values.add(v.cls) + else: + typed_values.add(v) + # Where a concrete type conflicts with deductions, the usage of # attributes cannot be supported and is thus impossible. - if value: - if types and value not in types: + if typed_values: + if types and not typed_values.intersection(types): node._guard_types[name] = "impossible" else: - node._guard_types[name] = "single" - node._guards[name] = set([value]) + node._guard_types[name] = len(typed_values) == 1 and "single" or "multiple" + node._guards[name] = typed_values # Where no concrete type is known, usage must be checked.