Fix some broken constructors.
[nit.git] / src / metamodel / static_type.nit
index 2720fa4..bf4616f 100644 (file)
@@ -160,6 +160,42 @@ class MMSignature
                return new MMSignature(p,rv,r)
        end
 
+       attr _not_for_self_cache: MMSignature
+
+       # Return a type approximation if the reveiver is not self
+       # Useful for virtual types
+       meth not_for_self: MMSignature
+       do
+               var res = _not_for_self_cache
+               if res != null then return res
+
+               var need_for_self = false
+               var p = _params
+               if p != null then
+                       p = new Array[MMType]
+                       for i in _params do
+                               var i2 = i.not_for_self
+                               if i != i2 then need_for_self = true
+                               p.add(i.not_for_self)
+                       end
+               end
+               
+               var rv = _return_type
+               if rv != null then
+                       var rv = rv.not_for_self
+                       if rv != _return_type then need_for_self = true
+               end
+
+               if need_for_self then
+                       res = new MMSignature(p, rv, _recv)
+               else
+                       res = self
+               end
+
+               _not_for_self_cache = res
+               return res
+       end
+
        init(params: Array[MMType], return_type: MMType, r: MMType)
        do
                assert params != null
@@ -172,10 +208,10 @@ end
 # Inheritance relation between two types
 abstract class MMAncestor
        # The inherited type
-       readable writable attr _stype: MMType 
+       readable writable attr _stype: MMType = null 
 
        # The inheriter (heir) type
-       readable writable attr _inheriter: MMType 
+       readable writable attr _inheriter: MMType  = null
 
        meth is_reffinement: Bool do
                return stype.module != stype.module
@@ -280,7 +316,7 @@ special MMTypeClass
 
        redef meth adapt_to(recv) do return self
 
-       redef init(c: MMLocalClass)
+       init(c: MMLocalClass)
        do
                super(c)
        end