From 43e788439e7c634a63ac92804de877679b7ccd69 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 26 Jun 2024 21:01:56 -0400 Subject: [PATCH] tests: add a new unreachable statement relates test Signed-off-by: Jean Privat --- tests/base_control_flow3.nit | 49 +++++++++++++++++++++++++++ tests/sav/base_control_flow3.res | 2 ++ tests/sav/base_control_flow3_alt1.res | 3 ++ 3 files changed, 54 insertions(+) create mode 100644 tests/base_control_flow3.nit create mode 100644 tests/sav/base_control_flow3.res create mode 100644 tests/sav/base_control_flow3_alt1.res diff --git a/tests/base_control_flow3.nit b/tests/base_control_flow3.nit new file mode 100644 index 0000000000..1e17ae1871 --- /dev/null +++ b/tests/base_control_flow3.nit @@ -0,0 +1,49 @@ +# 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 kernel + +var a +a = null +a = 1 + +a.output +return +# Below this line the code is unreachable + +var b +b = null +b = 1 +a.output +b.output +a = b +b = a + +if a == b then + a = b + b = a +else + a = null + b = null +end +a.output +b.output +var c = a.as(not null) +var d = b.as(Int) +var e +e.output + +#alt1#(b+1).output # Error +b = 1 +#alt1#(b+1).output # Still error diff --git a/tests/sav/base_control_flow3.res b/tests/sav/base_control_flow3.res new file mode 100644 index 0000000000..e3ec4cf81b --- /dev/null +++ b/tests/sav/base_control_flow3.res @@ -0,0 +1,2 @@ +base_control_flow3.nit:25,1--5: Warning: unreachable statement. +1 diff --git a/tests/sav/base_control_flow3_alt1.res b/tests/sav/base_control_flow3_alt1.res new file mode 100644 index 0000000000..25a65d9e64 --- /dev/null +++ b/tests/sav/base_control_flow3_alt1.res @@ -0,0 +1,3 @@ +alt/base_control_flow3_alt1.nit:25,1--5: Warning: unreachable statement. +alt/base_control_flow3_alt1.nit:47,3: Error: method `+` does not exists in `nullable Object`. +alt/base_control_flow3_alt1.nit:49,3: Error: method `+` does not exists in `nullable Object`.