model: add annotation `fixed` on virtual types
authorJean Privat <jean@pryen.org>
Tue, 22 Jul 2014 19:07:56 +0000 (15:07 -0400)
committerJean Privat <jean@pryen.org>
Wed, 23 Jul 2014 01:12:26 +0000 (21:12 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/model/model.nit
src/modelize_property.nit

index 7568e9b..894278a 100644 (file)
@@ -1945,6 +1945,9 @@ class MVirtualTypeDef
 
        # The bound of the virtual type
        var bound: nullable MType writable = null
+
+       # Is the bound fixed?
+       var is_fixed writable = false
 end
 
 # A kind of class.
index 93f0e00..f4f8661 100644 (file)
@@ -975,6 +975,11 @@ redef class ATypePropdef
                self.mpropdef = mpropdef
                modelbuilder.mpropdef2npropdef[mpropdef] = self
                set_doc(mpropdef)
+
+               var atfixed = get_single_annotation("fixed", modelbuilder)
+               if atfixed != null then
+                       mpropdef.is_fixed = true
+               end
        end
 
        redef fun build_signature(modelbuilder)
@@ -1028,6 +1033,10 @@ redef class ATypePropdef
                bound = mpropdef.bound.as(not null)
                for p in mpropdef.mproperty.lookup_super_definitions(mmodule, anchor) do
                        var supbound = p.bound.as(not null)
+                       if p.is_fixed then
+                               modelbuilder.error(self, "Redef Error: Virtual type {mpropdef.mproperty} is fixed in super-class {p.mclassdef.mclass}")
+                               break
+                       end
                        if p.mclassdef.mclass == mclassdef.mclass then
                                # Still a warning to pass existing bad code
                                modelbuilder.warning(n_type, "Redef Error: a virtual type cannot be refined.")