From 8063bf08cda164c2c31515a5a5e8195008c067cf Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Fri, 3 Jul 2009 22:44:29 -0400 Subject: [PATCH] syntax: do not processes erroneous signatures Signed-off-by: Jean Privat --- src/syntax/mmbuilder.nit | 24 +++++++++++++++++++--- tests/error_type_not_ok4.nit | 35 +++++++++++++++++++++++++++++++++ tests/sav/error_type_not_ok4.sav | 7 +++++++ tests/sav/error_type_not_ok4_alt1.sav | 7 +++++++ 4 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 tests/error_type_not_ok4.nit create mode 100644 tests/sav/error_type_not_ok4.sav create mode 100644 tests/sav/error_type_not_ok4_alt1.sav diff --git a/src/syntax/mmbuilder.nit b/src/syntax/mmbuilder.nit index af4d0e2..228d9c9 100644 --- a/src/syntax/mmbuilder.nit +++ b/src/syntax/mmbuilder.nit @@ -391,6 +391,9 @@ private class SignatureBuilder # Current closure declarations readable writable var _closure_decls: Array[AClosureDecl] = new Array[AClosureDecl] + # True is a problen occured durring building + readable writable var _has_error_occured: Bool = false + # Current signature readable writable var _signature: nullable MMSignature = null end @@ -777,7 +780,7 @@ redef class PPropdef var supers = prop.local_class.super_methods_named(prop.name) inherit_signature(v, prop, supers) end - if prop.signature != null then + if prop.signature != null or v.signature_builder.has_error_occured then # ok else if not v.signature_builder.untyped_params.is_empty then v.error(v.signature_builder.untyped_params.first, "Error: Untyped parameter.") @@ -1009,6 +1012,8 @@ redef class AMethPropdef v.signature_builder = new SignatureBuilder super + if v.signature_builder.has_error_occured then return + if v.signature_builder.signature == null then #_method.signature = new MMSignature(new Array[MMType], null, v.local_class.get_type) else @@ -1105,7 +1110,9 @@ redef class ASignature redef fun accept_property_verifier(v) do super - if not v.signature_builder.untyped_params.is_empty then + if v.signature_builder.has_error_occured then + return + else if not v.signature_builder.untyped_params.is_empty then if v.signature_builder.untyped_params.first != v.signature_builder.params.first or n_type != null then v.error(v.signature_builder.untyped_params.first, "Syntax error: untyped parameter.") return @@ -1118,6 +1125,10 @@ redef class ASignature var ret: nullable MMType = null if n_type != null then ret = n_type.get_stype(v) + if ret == null then + v.signature_builder.has_error_occured = true + return + end end v.signature_builder.signature = new MMSignature(pars, ret, v.local_class.get_type) if v.signature_builder.vararg_rank >= 0 then @@ -1156,7 +1167,11 @@ redef class PParam v.signature_builder.params.add(self) v.signature_builder.untyped_params.add(self) if n_type != null then - var stype = n_type.get_stype(v).as(not null) + var stype = n_type.get_stype(v) + if stype == null then + v.signature_builder.has_error_occured = true + return + end for p in v.signature_builder.untyped_params do p.stype = stype if is_vararg then @@ -1189,6 +1204,9 @@ redef class AClosureDecl var old_signature_builder = v.signature_builder v.signature_builder = new SignatureBuilder super + if v.signature_builder.has_error_occured then + return + end var sig = v.signature_builder.signature if sig == null then sig = new MMSignature(new Array[MMType], null, v.local_class.get_type) diff --git a/tests/error_type_not_ok4.nit b/tests/error_type_not_ok4.nit new file mode 100644 index 0000000..4762921 --- /dev/null +++ b/tests/error_type_not_ok4.nit @@ -0,0 +1,35 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2009 Jean Privat +# +# 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. + +#alt1#class Fail[E] +#alt1#end + +class E + type T: Fail +end + +class F + type T: Array[Fail] +end + +class G + readable writable var _a: Fail + fun ma(a: Fail) do return + fun mb(a: Array[Fail]) do return + fun mc: Fail do return 0 + fun md: Array[Fail] do return 0 +end + diff --git a/tests/sav/error_type_not_ok4.sav b/tests/sav/error_type_not_ok4.sav new file mode 100644 index 0000000..6e788b7 --- /dev/null +++ b/tests/sav/error_type_not_ok4.sav @@ -0,0 +1,7 @@ +./error_type_not_ok4.nit:25,16: Type error: class Fail not found in module error_type_not_ok4. +./error_type_not_ok4.nit:29,28: Type error: class Fail not found in module error_type_not_ok4. +./error_type_not_ok4.nit:30,12: Type error: class Fail not found in module error_type_not_ok4. +./error_type_not_ok4.nit:31,18: Type error: class Fail not found in module error_type_not_ok4. +./error_type_not_ok4.nit:32,10: Type error: class Fail not found in module error_type_not_ok4. +./error_type_not_ok4.nit:33,16: Type error: class Fail not found in module error_type_not_ok4. +./error_type_not_ok4.nit:21,10: Type error: class Fail not found in module error_type_not_ok4. diff --git a/tests/sav/error_type_not_ok4_alt1.sav b/tests/sav/error_type_not_ok4_alt1.sav new file mode 100644 index 0000000..96912f0 --- /dev/null +++ b/tests/sav/error_type_not_ok4_alt1.sav @@ -0,0 +1,7 @@ +alt/error_type_not_ok4_alt1.nit:21,10--13: Type error: 'Fail' is a generic class. +alt/error_type_not_ok4_alt1.nit:25,16--19: Type error: 'Fail' is a generic class. +alt/error_type_not_ok4_alt1.nit:29,28--31: Type error: 'Fail' is a generic class. +alt/error_type_not_ok4_alt1.nit:30,12--15: Type error: 'Fail' is a generic class. +alt/error_type_not_ok4_alt1.nit:31,18--21: Type error: 'Fail' is a generic class. +alt/error_type_not_ok4_alt1.nit:32,10--13: Type error: 'Fail' is a generic class. +alt/error_type_not_ok4_alt1.nit:33,16--19: Type error: 'Fail' is a generic class. -- 1.7.9.5