model: protect MClassDef.is_intro and provide MClass.try_intro
authorJean Privat <jean@pryen.org>
Fri, 3 Apr 2015 02:34:01 +0000 (09:34 +0700)
committerJean Privat <jean@pryen.org>
Fri, 3 Apr 2015 06:09:35 +0000 (13:09 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>

src/model/model.nit

index 76a3839..754f57a 100644 (file)
@@ -433,8 +433,17 @@ class MClass
        #
        # Warning: such a definition may not exist in the early life of the object.
        # In this case, the method will abort.
+       #
+       # Use `try_intro` instead
        var intro: MClassDef is noinit
 
+       # The definition that introduces the class or null if not yet known.
+       #
+       # See `intro`
+       fun try_intro: nullable MClassDef do
+               if isset _intro then return _intro else return null
+       end
+
        # Return the class `self` in the class hierarchy of the module `mmodule`.
        #
        # SEE: `MModule::flatten_mclass_hierarchy`
@@ -627,7 +636,7 @@ class MClassDef
        var in_hierarchy: nullable POSetElement[MClassDef] = null
 
        # Is the definition the one that introduced `mclass`?
-       fun is_intro: Bool do return mclass.intro == self
+       fun is_intro: Bool do return isset mclass._intro and mclass.intro == self
 
        # All properties introduced by the classdef
        var intro_mproperties = new Array[MProperty]