From 3eb34f970636b2c696dd51dddba56ada6c0ccb1d Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 5 Apr 2018 14:05:46 -0400 Subject: [PATCH] nitc: do not autocast primitive types Signed-off-by: Jean Privat --- src/compiler/abstract_compiler.nit | 5 +++++ tests/base_autocast_prim.nit | 24 ++++++++++++++++++++++++ tests/sav/base_autocast_prim.res | 1 + 3 files changed, 30 insertions(+) create mode 100644 tests/base_autocast_prim.nit create mode 100644 tests/sav/base_autocast_prim.res diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 11e4790..ac6edce 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -1392,6 +1392,11 @@ abstract class AbstractCompilerVisitor mtype = self.anchor(mtype) var valmtype = value.mcasttype + # CPrimitive is the best you can do + if valmtype.is_c_primitive then + return value + end + # Do nothing if useless autocast if valmtype.is_subtype(self.compiler.mainmodule, null, mtype) then return value diff --git a/tests/base_autocast_prim.nit b/tests/base_autocast_prim.nit new file mode 100644 index 0000000..4dd1e34 --- /dev/null +++ b/tests/base_autocast_prim.nit @@ -0,0 +1,24 @@ +# 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 + +var bool = true +var int = 42 + +assert int isa Bool + +if int == bool then + 1.output +end diff --git a/tests/sav/base_autocast_prim.res b/tests/sav/base_autocast_prim.res new file mode 100644 index 0000000..1a261b5 --- /dev/null +++ b/tests/sav/base_autocast_prim.res @@ -0,0 +1 @@ +Runtime error: Assert failed (base_autocast_prim.nit:20) -- 1.7.9.5