From: Jean-Christophe Beaupré Date: Fri, 24 Mar 2017 04:42:41 +0000 (-0400) Subject: model: Make the `anchor` parameter of `MType::anchor_to` nullable X-Git-Url: http://nitlanguage.org model: Make the `anchor` parameter of `MType::anchor_to` nullable Refactor the code of `TypeVisitor::anchor_to`. Signed-off-by: Jean-Christophe Beaupré --- diff --git a/src/model/model.nit b/src/model/model.nit index 35910d3..03d82b14 100644 --- a/src/model/model.nit +++ b/src/model/model.nit @@ -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 diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index 0bbe61b..d5cbb46 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -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