nullable: convert lib, tools and tests
[nit.git] / src / metamodel / virtualtype.nit
index 7205be8..12a85d7 100644 (file)
@@ -29,9 +29,9 @@ end
 class MMTypeProperty
 special MMLocalProperty
        # The virtual static type associated
-       meth stype_for(recv: MMType): MMVirtualType
+       meth stype_for(recv: MMType): nullable MMVirtualType
        do
-               var prop = recv.select_property(global)
+               var prop = recv.local_class[global]
                assert prop isa MMTypeProperty
                return prop.real_stype_for(recv)
        end
@@ -39,7 +39,7 @@ special MMLocalProperty
        # Cached results of stype
        attr _stypes_cache: HashMap[MMType, MMVirtualType] = new HashMap[MMType, MMVirtualType]
 
-       private meth real_stype_for(recv: MMType): MMVirtualType
+       private meth real_stype_for(recv: MMType): nullable MMVirtualType
        do
                # If the signature is not build: Circular definition
                if signature == null then return null
@@ -53,18 +53,6 @@ special MMLocalProperty
        end
 end
 
-redef class MMType
-       # Select a virtual type property by its name
-       meth select_virtual_type(name: Symbol): MMTypeProperty
-       do
-               assert local_class != null
-               assert name != null
-               var res = select_property(local_class.virtual_type(name))
-               assert res isa MMTypeProperty
-               return res
-       end
-end
-
 class MMVirtualType
 special MMTypeFormal
        # The property associed
@@ -95,7 +83,7 @@ special MMTypeFormal
 
        redef meth adapt_to(recv)
        do
-               return property.stype_for(recv)
+               return property.stype_for(recv).as(not null)
        end
 end
 
@@ -106,6 +94,15 @@ redef class MMLocalClass
                if prop.is_virtual_type then
                        return prop
                end
-               return null
+               abort
+       end
+
+       # Select a virtual type property by its name
+       meth select_virtual_type(name: Symbol): MMTypeProperty
+       do
+               var gp = virtual_type(name)
+               var res = self[gp]
+               assert res isa MMTypeProperty
+               return res
        end
 end