From 081a3a3779310ed82490a1dc14e251d793d3bcf4 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Thu, 20 Feb 2014 10:45:05 -0500 Subject: [PATCH] nitg: Fixed modelize_property to print an error when two redefs of the same method occur locally. Signed-off-by: Lucas Bajolet --- src/modelize_property.nit | 18 ++++++++++++++++++ tests/base_error_doubledef.nit | 29 +++++++++++++++++++++++++++++ tests/sav/base_error_doubledef.res | 1 + 3 files changed, 48 insertions(+) create mode 100644 tests/base_error_doubledef.nit create mode 100644 tests/sav/base_error_doubledef.res diff --git a/src/modelize_property.nit b/src/modelize_property.nit index 7e83e4b..2b184b1 100644 --- a/src/modelize_property.nit +++ b/src/modelize_property.nit @@ -158,6 +158,10 @@ redef class MClass var inherit_init_from: nullable MClass = null end +redef class MClassDef + private var propdef_names = new HashSet[String] +end + redef class AClassdef var build_properties_is_done: Bool = false # The list of super-constructor to call at the start of the free constructor @@ -392,6 +396,20 @@ redef class AMethPropdef var mpropdef = new MMethodDef(mclassdef, mprop, self.location) + if mclassdef.propdef_names.has(mprop.name) then + var loc: nullable Location = null + for i in mclassdef.mpropdefs do + if i.mproperty.name == mprop.name then + loc = i.location + break + end + end + if loc == null then abort + modelbuilder.error(self, "Error: a property {mprop} is already defined in class {mclassdef.mclass} at {loc}") + end + + mclassdef.propdef_names.add(mpropdef.mproperty.name) + self.mpropdef = mpropdef modelbuilder.mpropdef2npropdef[mpropdef] = self if mpropdef.is_intro then diff --git a/tests/base_error_doubledef.nit b/tests/base_error_doubledef.nit new file mode 100644 index 0000000..a0961db --- /dev/null +++ b/tests/base_error_doubledef.nit @@ -0,0 +1,29 @@ +# 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 end + +class A + fun foo do end +end + +class B + super A + + redef fun foo do end + + redef fun foo do end + +end + diff --git a/tests/sav/base_error_doubledef.res b/tests/sav/base_error_doubledef.res new file mode 100644 index 0000000..ed17cab --- /dev/null +++ b/tests/sav/base_error_doubledef.res @@ -0,0 +1 @@ +base_error_doubledef.nit:26,12--14: Error: a property foo is already defined in class B at base_error_doubledef.nit:24,2--21 -- 1.7.9.5