From: Jean Privat Date: Thu, 5 Apr 2018 18:05:46 +0000 (-0400) Subject: nitc: do not autocast primitive types X-Git-Url: http://nitlanguage.org nitc: do not autocast primitive types Signed-off-by: Jean Privat --- 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)