From: Jean Privat Date: Thu, 2 Mar 2017 21:06:45 +0000 (-0500) Subject: nitc/typing: isa uses intersect_types and diff_types X-Git-Url: http://nitlanguage.org nitc/typing: isa uses intersect_types and diff_types Signed-off-by: Jean Privat --- diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index 7c1adf4..9813284 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -1788,9 +1788,16 @@ redef class AIsaExpr #var to = if mtype != null then mtype.to_s else "invalid" #debug("adapt {variable}: {from} -> {to}") - # Do not adapt if there is no information gain (i.e. adapt to a supertype) - if mtype == null or orig == null or not v.is_subtype(orig, mtype) then - self.after_flow_context.when_true.set_var(v, variable, mtype) + var thentype = v.intersect_types(self, orig, mtype) + if thentype != orig then + self.after_flow_context.when_true.set_var(v, variable, thentype) + #debug "{variable}:{orig or else "?"} isa {mtype or else "?"} -> then {thentype or else "?"}" + end + + var elsetype = v.diff_types(self, orig, mtype) + if elsetype != orig then + self.after_flow_context.when_false.set_var(v, variable, elsetype) + #debug "{variable}:{orig or else "?"} isa {mtype or else "?"} -> else {elsetype or else "?"}" end end