1.1 --- a/micropython/deduce.py Thu May 01 23:03:06 2014 +0200
1.2 +++ b/micropython/deduce.py Sat May 10 17:26:04 2014 +0200
1.3 @@ -22,7 +22,7 @@
1.4 from micropython.stdcompiler import compiler
1.5 from compiler.ast import *
1.6
1.7 -from micropython.basicdata import Const, Constant, TypedInstance
1.8 +from micropython.basicdata import Constant, TypedInstance
1.9 from micropython.common import ASTVisitor, used_by_unit
1.10 from micropython.data import *
1.11 from micropython.errors import *
1.12 @@ -568,15 +568,32 @@
1.13 types = self.get_targets_from_type_names(node._attrtypes.get(name))
1.14 value = node._values.get(name)
1.15
1.16 + if isinstance(value, BaseAttr):
1.17 + values = value.get_values()
1.18 + else:
1.19 + values = [value]
1.20 +
1.21 + # Obtain values with identifiable types.
1.22 +
1.23 + typed_values = set()
1.24 +
1.25 + for v in values:
1.26 + if isinstance(v, Instance):
1.27 + if not isinstance(v, TypedInstance):
1.28 + return
1.29 + typed_values.add(v.cls)
1.30 + else:
1.31 + typed_values.add(v)
1.32 +
1.33 # Where a concrete type conflicts with deductions, the usage of
1.34 # attributes cannot be supported and is thus impossible.
1.35
1.36 - if value:
1.37 - if types and value not in types:
1.38 + if typed_values:
1.39 + if types and not typed_values.intersection(types):
1.40 node._guard_types[name] = "impossible"
1.41 else:
1.42 - node._guard_types[name] = "single"
1.43 - node._guards[name] = set([value])
1.44 + node._guard_types[name] = len(typed_values) == 1 and "single" or "multiple"
1.45 + node._guards[name] = typed_values
1.46
1.47 # Where no concrete type is known, usage must be checked.
1.48