model: Make the `anchor` parameter of `MType::anchor_to` nullable
authorJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Fri, 24 Mar 2017 04:42:41 +0000 (00:42 -0400)
committerJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Sun, 26 Mar 2017 03:43:25 +0000 (23:43 -0400)
Refactor the code of `TypeVisitor::anchor_to`.

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

src/model/model.nit
src/semantize/typing.nit

index 35910d3..03d82b1 100644 (file)
@@ -904,12 +904,13 @@ abstract class MType
        # because "redef type U: Y". Therefore, Map[T, U] is bound to
        # Map[B, Y]
        #
+       # REQUIRE: `self.need_anchor implies anchor != null`
        # ENSURE: `not self.need_anchor implies result == self`
        # ENSURE: `not result.need_anchor`
-       fun anchor_to(mmodule: MModule, anchor: MClassType): MType
+       fun anchor_to(mmodule: MModule, anchor: nullable MClassType): MType
        do
                if not need_anchor then return self
-               assert not anchor.need_anchor
+               assert anchor != null and not anchor.need_anchor
                # Just resolve to the anchor and clear all the virtual types
                var res = self.resolve_for(anchor, null, mmodule, true)
                assert not res.need_anchor
@@ -1220,7 +1221,7 @@ class MClassType
 
        redef fun need_anchor do return false
 
-       redef fun anchor_to(mmodule: MModule, anchor: MClassType): MClassType
+       redef fun anchor_to(mmodule, anchor): MClassType
        do
                return super.as(MClassType)
        end
index 0bbe61b..d5cbb46 100644 (file)
@@ -81,11 +81,6 @@ private class TypeVisitor
 
        fun anchor_to(mtype: MType): MType
        do
-               var anchor = anchor
-               if anchor == null then
-                       assert not mtype.need_anchor
-                       return mtype
-               end
                return mtype.anchor_to(mmodule, anchor)
        end