From 2d04d78ff1f7ec1ebc415218af4e64a558d51ce2 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Sat, 25 Jun 2016 12:03:57 -0400 Subject: [PATCH] typing: `isa` do not adapt to a supertype. Signed-off-by: Jean Privat --- src/semantize/typing.nit | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index 6c4de01..73e1bd0 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -1666,11 +1666,15 @@ redef class AIsaExpr var variable = self.n_expr.its_variable if variable != null then - #var orig = self.n_expr.mtype + var orig = self.n_expr.mtype #var from = if orig != null then orig.to_s else "invalid" #var to = if mtype != null then mtype.to_s else "invalid" #debug("adapt {variable}: {from} -> {to}") - self.after_flow_context.when_true.set_var(v, variable, mtype) + + # 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) + end end self.mtype = v.type_bool(self) -- 1.7.9.5