Merge: model: Do not assume enums to be final
authorJean Privat <jean@pryen.org>
Thu, 25 May 2017 14:55:21 +0000 (10:55 -0400)
committerJean Privat <jean@pryen.org>
Thu, 25 May 2017 14:55:21 +0000 (10:55 -0400)
An upcoming feature will destroy this assumption.

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

Pull-Request: #2458

lib/opts.nit
src/metrics/metrics_base.nit
src/model/model.nit
tests/base_ret_covar_int.nit
tests/example_sorter.nit
tests/sav/base_virtual_type_self_alt2.res

index c93d39a..a7789f8 100644 (file)
@@ -127,7 +127,7 @@ end
 # A count option. Count the number of time this option is present
 class OptionCount
        super Option
-       redef type VALUE: Int
+       redef type VALUE: Int is fixed
 
        # Init a new OptionCount with a `help` message and `names`.
        init(help: String, names: String...) is old_style_init do super(help, 0, names)
index a2fb201..216e2b3 100644 (file)
@@ -235,7 +235,7 @@ end
 class IntMetric
        super Metric
 
-       redef type VAL: Int
+       redef type VAL: Int is fixed
        redef type RES: Counter[ELM]
 
        # `IntMetric` uses a Counter to store values in intern.
index 2f16bc5..21b182e 100644 (file)
@@ -1478,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
@@ -1493,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
@@ -1620,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.
@@ -1641,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)
index 6681b3d..002956f 100644 (file)
@@ -35,7 +35,7 @@ class B
        redef fun bar2: Int do return 33
 
        redef fun baz1 do return 44
-       #alt1#redef fun baz2: Int do return 55
+       #alt1#redef fun baz2 do return 55
 end
 
 fun test_a(a: A[Object])
index ae839ed..7f43b63 100644 (file)
@@ -17,7 +17,7 @@
 
 class BackIntComparator
        super Comparator
-       redef type COMPARED: Int
+       redef type COMPARED: Int is fixed
        redef fun compare(a: Int, b: Int): Int
        do
                return b <=> a
@@ -28,7 +28,7 @@ end
 
 class DecimalComparator
        super Comparator
-       redef type COMPARED: Int
+       redef type COMPARED: Int is fixed
        redef fun compare(a: Int, b: Int): Int
        do
                return (a%10) <=> (b%10)
index 3eeff31..27b5633 100644 (file)
@@ -1,3 +1,3 @@
-alt/base_virtual_type_self_alt2.nit:44,9: Type Error: expected `Int`, got `Float`.
-alt/base_virtual_type_self_alt2.nit:45,7--12: Type Error: expected `Float`, got `Int`.
-alt/base_virtual_type_self_alt2.nit:47,7--12: Type Error: expected `Float`, got `A[Int]`.
+alt/base_virtual_type_self_alt2.nit:44,9: Type Error: expected `U`, got `Float`.
+alt/base_virtual_type_self_alt2.nit:45,7--12: Type Error: expected `Float`, got `U: Int`.
+alt/base_virtual_type_self_alt2.nit:47,7--12: Type Error: expected `Float`, got `A[U]: A[Int]`.