From 6585c92f335641a962f5d239b0264e0fb6a7b15e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Christophe=20Beaupr=C3=A9?= Date: Fri, 24 Mar 2017 00:42:41 -0400 Subject: [PATCH] model: Make the `anchor` parameter of `MType::anchor_to` nullable MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Refactor the code of `TypeVisitor::anchor_to`. Signed-off-by: Jean-Christophe Beaupré --- src/model/model.nit | 7 ++++--- src/semantize/typing.nit | 5 ----- 2 files changed, 4 insertions(+), 8 deletions(-) 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 -- 1.7.9.5