From f2a2692933abb3023afad05bf6f8d6cd6a869db3 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 28 Oct 2015 11:58:07 -0400 Subject: [PATCH] model: in case of error, methods of MVirtualType return a bottomtype Signed-off-by: Jean Privat --- src/model/model.nit | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/model/model.nit b/src/model/model.nit index 851efda..ccb7522 100644 --- a/src/model/model.nit +++ b/src/model/model.nit @@ -1010,7 +1010,7 @@ abstract class MType # The result is returned exactly as declared in the "type" property (verbatim). # So it could be another formal type. # - # In case of conflict, the method aborts. + # In case of conflicts or inconsistencies in the model, the method returns a `MBottomType`. fun lookup_bound(mmodule: MModule, resolved_receiver: MType): MType do return self # Resolve the formal type to its simplest equivalent form. @@ -1024,6 +1024,8 @@ abstract class MType # # By default, return self. # See the redefinitions for specific behavior in each kind of type. + # + # In case of conflicts or inconsistencies in the model, the method returns a `MBottomType`. fun lookup_fixed(mmodule: MModule, resolved_receiver: MType): MType do return self # Can the type be resolved? @@ -1365,7 +1367,7 @@ class MVirtualType redef fun lookup_bound(mmodule: MModule, resolved_receiver: MType): MType do - return lookup_single_definition(mmodule, resolved_receiver).bound.as(not null) + return lookup_single_definition(mmodule, resolved_receiver).bound or else new MBottomType(model) end private fun lookup_single_definition(mmodule: MModule, resolved_receiver: MType): MVirtualTypeDef @@ -1400,7 +1402,8 @@ class MVirtualType assert resolved_receiver isa MClassType # It is the only remaining type var prop = lookup_single_definition(mmodule, resolved_receiver) - var res = prop.bound.as(not null) + var res = prop.bound + if res == null then return new MBottomType(model) # Recursively lookup the fixed result res = res.lookup_fixed(mmodule, resolved_receiver) -- 1.7.9.5