From: Jean Privat Date: Fri, 25 Mar 2016 01:27:00 +0000 (-0400) Subject: nitc/abscomp: cleanup, document and fix autoadapt (no change) X-Git-Url: http://nitlanguage.org nitc/abscomp: cleanup, document and fix autoadapt (no change) The fix is do not change the static type on type adaptation! Signed-off-by: Jean Privat --- diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 3384473..5fca1a1 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -1273,17 +1273,21 @@ abstract class AbstractCompilerVisitor do mtype = self.anchor(mtype) var valmtype = value.mcasttype + + # Do nothing if useless autocast if valmtype.is_subtype(self.compiler.mainmodule, null, mtype) then return value end + # Just as_not_null if the target is not nullable. + # + # eg `nullable PreciseType` adapted to `Object` gives precisetype. if valmtype isa MNullableType and valmtype.mtype.is_subtype(self.compiler.mainmodule, null, mtype) then - var res = new RuntimeVariable(value.name, valmtype, valmtype.mtype) - return res - else - var res = new RuntimeVariable(value.name, valmtype, mtype) - return res + mtype = valmtype.mtype end + + var res = new RuntimeVariable(value.name, value.mtype, mtype) + return res end # Generate a super call from a method definition