1.1 --- a/micropython/deduce.py Mon Mar 17 22:37:22 2014 +0100
1.2 +++ b/micropython/deduce.py Mon Mar 17 22:40:50 2014 +0100
1.3 @@ -125,11 +125,13 @@
1.4 else:
1.5 exprs = [expr]
1.6
1.7 - # For each expression value try and get a concrete
1.8 - # attribute.
1.9 + # For each expression value try and get a concrete attribute.
1.10
1.11 - for expr in exprs:
1.12 - found_attr = expr.all_attributes().get(attrname)
1.13 + for _expr in exprs:
1.14 + if isinstance(_expr, Instance):
1.15 + continue
1.16 +
1.17 + found_attr = _expr.all_attributes().get(attrname)
1.18
1.19 # Where an attribute can be obtained, record its
1.20 # details.
1.21 @@ -283,6 +285,10 @@
1.22
1.23 node._access_attrs = attributes
1.24
1.25 + # Return the _attr annotation for instantiation detection.
1.26 +
1.27 + return node._attr
1.28 +
1.29 def _annotateAttr(self, node, target, attrname):
1.30
1.31 """
1.32 @@ -540,7 +546,7 @@
1.33 value = attr
1.34
1.35 if value and isinstance(value, Instance) and not isinstance(value, TypedInstance):
1.36 - node._values[node.name] = expr
1.37 + node._values[node.name] = expr or make_instance()
1.38
1.39 self._visitGuard(node)
1.40
1.41 @@ -554,6 +560,10 @@
1.42 "Make an annotation stating the acceptable types for a name."
1.43
1.44 # Need to check any concrete value against deductions.
1.45 + # Where no local observations exist, no guard can usefully be asserted.
1.46 +
1.47 + if not node._attrtypes and not node._values:
1.48 + return
1.49
1.50 types = self.get_targets_from_type_names(node._attrtypes.get(name))
1.51 value = node._values.get(name)
1.52 @@ -588,17 +598,18 @@
1.53
1.54 "Identify any concrete types involved with instantiation."
1.55
1.56 - for n in node.getChildNodes():
1.57 + for n in node.getChildNodes()[1:]: # ignore node.node
1.58 self.dispatch(n)
1.59
1.60 # Determine whether the target of the invocation refers to a class.
1.61
1.62 - attr = node.node._attr
1.63 + attr = self.dispatch(node.node)
1.64
1.65 - if attr and not isinstance(attr, Instance):
1.66 - value = attr.get_value()
1.67 - if value and isinstance(value, Class):
1.68 - return TypedInstance(value)
1.69 + if attr:
1.70 + if not isinstance(attr, (Instance, UnresolvedName)):
1.71 + value = attr.get_value()
1.72 + if value and isinstance(value, Class):
1.73 + return TypedInstance(value)
1.74
1.75 def _visitOperator(self, node):
1.76