if mclass == null then
mclass = new MClass(mmodule, name, arity, mkind, mvisibility)
#print "new class {mclass}"
+ else if nclassdef isa AStdClassdef and nmodule.mclass2nclassdef.has_key(mclass) then
+ error(nclassdef, "Error: A class {name} is already defined at line {nmodule.mclass2nclassdef[mclass].location.line_start}.")
+ return
else if nclassdef isa AStdClassdef and nclassdef.n_kwredef == null then
error(nclassdef, "Redef error: {name} is an imported class. Add the redef keyword to refine it.")
return
error(nvisibility, "Error: refinement changed the visibility from a {mclass.visibility} to a {mvisibility}")
end
nclassdef.mclass = mclass
+ nmodule.mclass2nclassdef[mclass] = nclassdef
end
# Visit the AST and create the MClassDef objects
var is_importation_done: Bool = false
# Flag that indicate if the class and prop building is already completed
var build_classes_is_done: Bool = false
+ # What is the AClassdef associated to a MClass?
+ # Used to check multiple definition of a class.
+ var mclass2nclassdef: Map[MClass, AClassdef] = new HashMap[MClass, AClassdef]
+
end
redef class MClass
--- /dev/null
+# 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.
+
+class A end
+class A end
+
--- /dev/null
+# 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 error_redef4_base
+
+redef class A end
+redef class A end
+
--- /dev/null
+# 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.
+
+class A end
+++ /dev/null
-error_cons_arity.nit:19,7: Redef error: C is an imported class. Add the redef keyword to refine it.
+++ /dev/null
-error_cons_arity2.nit:20,7: Redef error: A is an imported class. Add the redef keyword to refine it.
+++ /dev/null
-error_constraint.nit:20,7: Redef error: A is an imported class. Add the redef keyword to refine it.
+++ /dev/null
-alt/error_defs_alt6.nit:35,7: Redef error: A is an imported class. Add the redef keyword to refine it.
+++ /dev/null
-alt/error_defs_alt7.nit:25,6--8: Redef error: A::foo is an inherited property. To redefine it, add the redef keyword.
+++ /dev/null
-alt/error_defs_alt8.nit:25,6--8: Redef error: A::foo is an inherited property. To redefine it, add the redef keyword.
-alt/error_defs_alt8.nit:42,11--13: Error: No property A::foo is inherited. Remove the redef keyword to define a new property.
--- /dev/null
+error_redef3.nit:16,7: Error: A class A is already defined at line 15.
--- /dev/null
+error_redef4.nit:18,13: Error: A class A is already defined at line 17.
+++ /dev/null
-test_multiconstraint.nit:64,7: Redef error: G is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:70,7: Redef error: G is an imported class. Add the redef keyword to refine it.
+++ /dev/null
-test_multiconstraint.nit:19,7: Redef error: A is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:28,7: Redef error: B is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:42,7: Redef error: C is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:56,7: Redef error: G is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:64,7: Redef error: G is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:64,7: Redef error: G is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:70,7: Redef error: G is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:70,7: Redef error: G is an imported class. Add the redef keyword to refine it.
+++ /dev/null
-test_multiconstraint.nit:19,7: Redef error: A is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:28,7: Redef error: B is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:42,7: Redef error: C is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:56,7: Redef error: G is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:64,7: Redef error: G is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:64,7: Redef error: G is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:70,7: Redef error: G is an imported class. Add the redef keyword to refine it.
-test_multiconstraint.nit:70,7: Redef error: G is an imported class. Add the redef keyword to refine it.