modelize: mark property broken is they are bad introduction
authorJean Privat <jean@pryen.org>
Sat, 14 May 2016 15:23:21 +0000 (11:23 -0400)
committerJean Privat <jean@pryen.org>
Sat, 14 May 2016 15:23:21 +0000 (11:23 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/modelize/modelize_property.nit
tests/base_redef.nit [new file with mode: 0644]
tests/sav/base_redef.res [new file with mode: 0644]
tests/sav/base_redef_alt1.res [new file with mode: 0644]
tests/sav/base_redef_alt2.res [new file with mode: 0644]

index 87d3c81..246e813 100644 (file)
@@ -836,9 +836,7 @@ redef class AMethPropdef
                                return
                        end
                else
-                       if mprop.is_broken then
-                               return
-                       end
+                       if mprop.is_broken then return
                        if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, not self isa AMainMethPropdef, mprop) then return
                        check_redef_property_visibility(modelbuilder, self.n_visibility, mprop)
                end
@@ -1197,8 +1195,12 @@ redef class AAttrPropdef
                if mreadprop == null then
                        var mvisibility = new_property_visibility(modelbuilder, mclassdef, self.n_visibility)
                        mreadprop = new MMethod(mclassdef, readname, self.location, mvisibility)
-                       if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, false, mreadprop) then return
+                       if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, false, mreadprop) then
+                               mreadprop.is_broken = true
+                               return
+                       end
                else
+                       if mreadprop.is_broken then return
                        if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, true, mreadprop) then return
                        check_redef_property_visibility(modelbuilder, self.n_visibility, mreadprop)
                end
@@ -1296,9 +1298,13 @@ redef class AAttrPropdef
                                if mvisibility > protected_visibility then mvisibility = protected_visibility
                        end
                        mwriteprop = new MMethod(mclassdef, writename, self.location, mvisibility)
-                       if not self.check_redef_keyword(modelbuilder, mclassdef, nwkwredef, false, mwriteprop) then return
+                       if not self.check_redef_keyword(modelbuilder, mclassdef, nwkwredef, false, mwriteprop) then
+                               mwriteprop.is_broken = true
+                               return
+                       end
                        mwriteprop.deprecation = mreadprop.deprecation
                else
+                       if mwriteprop.is_broken then return
                        if not self.check_redef_keyword(modelbuilder, mclassdef, nwkwredef or else n_kwredef, true, mwriteprop) then return
                        if atwritable != null then
                                check_redef_property_visibility(modelbuilder, atwritable.n_visibility, mwriteprop)
@@ -1608,6 +1614,7 @@ redef class ATypePropdef
                                break
                        end
                else
+                       if mprop.is_broken then return
                        assert mprop isa MVirtualTypeProp
                        check_redef_property_visibility(modelbuilder, self.n_visibility, mprop)
                end
diff --git a/tests/base_redef.nit b/tests/base_redef.nit
new file mode 100644 (file)
index 0000000..d42bfec
--- /dev/null
@@ -0,0 +1,65 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import core::kernel
+
+class A
+       fun f do 1.output
+       fun f2: Int do return 2
+       fun f2=(i:Int) do i.output
+       fun f3=(i:Int) do i.output
+       var v = 4
+       type T: A
+       fun t(t: T): T do return t
+end
+
+class B
+       super A#alt1#
+       redef fun f do 10.output
+       redef var f2 = 20
+       var f3 = 30 is redef writable
+       redef var v = 40
+       redef type T: B
+end
+
+class C
+       super B#alt2#
+       redef fun f do 100.output
+       redef var f2 = 200
+       redef var f3 = 300
+       redef var v = 400
+       redef type T: C
+
+end
+
+var a = new A
+a.f
+a.f2 = -2
+a.f2.output
+a.f3 = -3
+a.t(a).f
+
+a = new B
+a.f
+a.f2 = -2
+a.f2.output
+a.f3 = -3
+a.t(a).f
+
+a = new C
+a.f
+a.f2 = -2
+a.f2.output
+a.f3 = -3
+a.t(a).f
diff --git a/tests/sav/base_redef.res b/tests/sav/base_redef.res
new file mode 100644 (file)
index 0000000..3b792d6
--- /dev/null
@@ -0,0 +1,11 @@
+1
+-2
+2
+-3
+1
+10
+-2
+10
+100
+-2
+100
diff --git a/tests/sav/base_redef_alt1.res b/tests/sav/base_redef_alt1.res
new file mode 100644 (file)
index 0000000..50e360c
--- /dev/null
@@ -0,0 +1,5 @@
+alt/base_redef_alt1.nit:29,12: Error: no property `B::f` is inherited. Remove the `redef` keyword to define a new property.
+alt/base_redef_alt1.nit:30,12--13: Error: no property `B::f2` is inherited. Remove the `redef` keyword to define a new property.
+alt/base_redef_alt1.nit:31,6--7: Error: no property `B::f3=` is inherited. Remove the `redef` keyword to define a new property.
+alt/base_redef_alt1.nit:32,12: Error: no property `B::v` is inherited. Remove the `redef` keyword to define a new property.
+alt/base_redef_alt1.nit:33,2--16: Error: no property `B::T` is inherited. Remove the `redef` keyword to define a new property.
diff --git a/tests/sav/base_redef_alt2.res b/tests/sav/base_redef_alt2.res
new file mode 100644 (file)
index 0000000..1c263c4
--- /dev/null
@@ -0,0 +1,5 @@
+alt/base_redef_alt2.nit:38,12: Error: no property `C::f` is inherited. Remove the `redef` keyword to define a new property.
+alt/base_redef_alt2.nit:39,12--13: Error: no property `C::f2` is inherited. Remove the `redef` keyword to define a new property.
+alt/base_redef_alt2.nit:40,12--13: Error: no property `C::f3` is inherited. Remove the `redef` keyword to define a new property.
+alt/base_redef_alt2.nit:41,12: Error: no property `C::v` is inherited. Remove the `redef` keyword to define a new property.
+alt/base_redef_alt2.nit:42,2--16: Error: no property `C::T` is inherited. Remove the `redef` keyword to define a new property.