modelize_class: Minimize the context used to resolve supertypes
[nit.git] / src / model / model.nit
index 8fb09ee..af53e3d 100644 (file)
@@ -177,7 +177,7 @@ redef class MModule
        # Visibility is not considered.
        #
        # Note: this function is expensive and is usually used for the main
-       # module of a program only. Do not use it to do you own subtype
+       # module of a program only. Do not use it to do your own subtype
        # functions.
        fun flatten_mclass_hierarchy: POSet[MClass]
        do
@@ -372,8 +372,8 @@ end
 
 # A named class
 #
-# `MClass` are global to the model; it means that a `MClass` is not bound to a
-# specific `MModule`.
+# `MClass`es are global to the model; it means that a `MClass` is not bound
+# to a specific `MModule`.
 #
 # This characteristic helps the reasoning about classes in a program since a
 # single `MClass` object always denote the same class.
@@ -477,11 +477,13 @@ class MClass
        end
 
        # The kind of the class (interface, abstract class, etc.)
-       # In Nit, the kind of a class cannot evolve in refinements
+       #
+       # In Nit, the kind of a class cannot evolve in refinements.
        var kind: MClassKind
 
        # The visibility of the class
-       # In Nit, the visibility of a class cannot evolve in refinements
+       #
+       # In Nit, the visibility of a class cannot evolve in refinements.
        redef var visibility
 
        init
@@ -505,12 +507,12 @@ 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
+       # Use `try_intro` instead.
        var intro: MClassDef is noinit
 
-       # The definition that introduces the class or null if not yet known.
+       # The definition that introduces the class or `null` if not yet known.
        #
-       # See `intro`
+       # SEE: `intro`
        fun try_intro: nullable MClassDef do
                if isset _intro then return _intro else return null
        end
@@ -1476,8 +1478,8 @@ class MVirtualType
 
        # A VT is fixed when:
        # * the VT is (re-)defined with the annotation `is fixed`
-       # * the VT is (indirectly) bound to an enum class (see `enum_kind`) since there is no subtype possible
-       # * the receiver is an enum class since there is no subtype possible
+       # * the receiver is an enum class since there is no subtype that can
+       #   redefine this virtual type
        redef fun lookup_fixed(mmodule: MModule, resolved_receiver: MType): MType
        do
                assert not resolved_receiver.need_anchor
@@ -1491,13 +1493,10 @@ class MVirtualType
                # Recursively lookup the fixed result
                res = res.lookup_fixed(mmodule, resolved_receiver)
 
-               # 1. For a fixed VT, return the resolved bound
+               # For a fixed VT, return the resolved bound
                if prop.is_fixed then return res
 
-               # 2. For a enum boud, return the bound
-               if res isa MClassType and res.mclass.kind == enum_kind then return res
-
-               # 3. for a enum receiver return the bound
+               # For a enum receiver return the bound
                if resolved_receiver.mclass.kind == enum_kind then return res
 
                return self
@@ -1618,9 +1617,7 @@ class MParameterType
        end
 
        # A PT is fixed when:
-       # * Its bound is a enum class (see `enum_kind`).
-       #   The PT is just useless, but it is still a case.
-       # * More usually, the `resolved_receiver` is a subclass of `self.mclass`,
+       # * The `resolved_receiver` is a subclass of `self.mclass`,
        #   so it is necessarily fixed in a `super` clause, either with a normal type
        #   or with another PT.
        #   See `resolve_for` for examples about related issues.
@@ -1639,13 +1636,7 @@ class MParameterType
                #print "{class_name}: {self}/{mtype}/{anchor}?"
 
                if mtype isa MGenericType and mtype.mclass == self.mclass then
-                       var res = mtype.arguments[self.rank]
-                       if anchor != null and res.need_anchor then
-                               # Maybe the result can be resolved more if are bound to a final class
-                               var r2 = res.anchor_to(mmodule, anchor)
-                               if r2 isa MClassType and r2.mclass.kind == enum_kind then return r2
-                       end
-                       return res
+                       return mtype.arguments[self.rank]
                end
 
                # self is a parameter type of mtype (or of a super-class of mtype)
@@ -2439,11 +2430,9 @@ abstract class MPropDef
                                        res.append "::"
                                end
                        end
-                       if mclassdef.mclass != mproperty.intro_mclassdef.mclass then
-                               # precise "B" only if not the same class than "A"
-                               res.append mproperty.intro_mclassdef.name
-                               res.append "::"
-                       end
+                       # precise "B" because it is not the same class than "A"
+                       res.append mproperty.intro_mclassdef.name
+                       res.append "::"
                        # Always use the property name "x"
                        res.append mproperty.name
                end
@@ -2461,10 +2450,8 @@ abstract class MPropDef
                                res.append mproperty.intro_mclassdef.mmodule.c_name
                                res.append "__"
                        end
-                       if mclassdef.mclass != mproperty.intro_mclassdef.mclass then
-                               res.append mproperty.intro_mclassdef.name.to_cmangle
-                               res.append "__"
-                       end
+                       res.append mproperty.intro_mclassdef.name.to_cmangle
+                       res.append "__"
                        res.append mproperty.name.to_cmangle
                end
                return res.to_s
@@ -2586,7 +2573,7 @@ class MClassKind
 
        # TODO: private init because enumeration.
 
-       # Can a class of kind `self` specializes a class of kine `other`?
+       # Can a class of kind `self` specializes a class of kind `other`?
        fun can_specialize(other: MClassKind): Bool
        do
                if other == interface_kind then return true # everybody can specialize interfaces