rta: consider type tests for covariant signatures
authorJean Privat <jean@pryen.org>
Thu, 29 Nov 2012 04:06:34 +0000 (23:06 -0500)
committerJean Privat <jean@pryen.org>
Thu, 29 Nov 2012 19:01:38 +0000 (14:01 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/rapid_type_analysis.nit

index 6be21eb..2a89d11 100644 (file)
@@ -102,6 +102,18 @@ class RapidTypeAnalysis
        # The customized method definitions that remain to visit
        private var todo: List[CustomizedMethodDef] = new List[CustomizedMethodDef]
 
+       # Adapt and remove nullable
+       # return null if we got the null type
+       fun cleanup_type(mtype: MType, recvtype: MClassType): nullable MClassType
+       do
+               mtype = mtype.anchor_to(self.mainmodule, recvtype)
+               if mtype isa MNullType then return null
+               if mtype isa MNullableType then mtype = mtype.mtype
+               assert mtype isa MClassType
+               assert not mtype.need_anchor
+               return mtype
+       end
+
        # Add a live type to the pool
        #
        # If the types is already live, then do nothing.
@@ -219,6 +231,14 @@ class RapidTypeAnalysis
                                self.add_type(native)
                        end
 
+                       for i in [0..mr.mmethoddef.msignature.arity[ do
+                               var origtype = mr.mmethoddef.mproperty.intro.msignature.mparameters[i].mtype
+                               if not origtype.need_anchor then continue # skip non covariant stuff
+                               var paramtype = mr.mmethoddef.msignature.mparameters[i].mtype
+                               paramtype = self.cleanup_type(paramtype, mr.receiver).as(not null)
+                               self.add_cast_type(paramtype)
+                       end
+
                        if not self.modelbuilder.mpropdef2npropdef.has_key(mr.mmethoddef) then
                                # It is an init for a class?
                                if mr.mmethoddef.mproperty.name == "init" then