From: Lucas Bajolet Date: Tue, 11 Feb 2014 21:10:40 +0000 (-0500) Subject: nitg: Corrected bug when creating a new AVarExpr, uses the last inferred type instead... X-Git-Tag: v0.6.4~34^2 X-Git-Url: http://nitlanguage.org nitg: Corrected bug when creating a new AVarExpr, uses the last inferred type instead of its definition type. Signed-off-by: Lucas Bajolet --- diff --git a/src/astbuilder.nit b/src/astbuilder.nit index e6182a0..0db3b4d 100644 --- a/src/astbuilder.nit +++ b/src/astbuilder.nit @@ -56,9 +56,9 @@ class ASTBuilder end # Make a new variable read - fun make_var_read(variable: Variable): AVarExpr + fun make_var_read(variable: Variable, mtype: MType): AVarExpr do - return new AVarExpr.make(variable) + return new AVarExpr.make(variable, mtype) end # Make a new variable assignment @@ -112,7 +112,7 @@ redef class AExpr place.replace_with(nvar) self.variable_cache = variable end - return new AVarExpr.make(variable) + return new AVarExpr.make(variable, variable.declared_type.as(not null)) end private var variable_cache: nullable Variable @@ -287,11 +287,11 @@ redef class AAttrAssignExpr end redef class AVarExpr - private init make(v: Variable) + private init make(v: Variable, mtype: MType) do _n_id = new TId variable = v - mtype = v.declared_type + self.mtype = mtype end end diff --git a/src/transform.nit b/src/transform.nit index f3200fa..4ec6635 100644 --- a/src/transform.nit +++ b/src/transform.nit @@ -289,7 +289,8 @@ redef class AVarReassignExpr do var variable = self.variable.as(not null) - var nread = v.builder.make_var_read(variable) + var nread = v.builder.make_var_read(variable, read_type.as(not null)) + var nnewvalue = v.builder.make_call(nread, reassign_callsite.mproperty, [n_value]) var nwrite = v.builder.make_var_assign(variable, nnewvalue) diff --git a/src/typing.nit b/src/typing.nit index 527f694..c760c74 100644 --- a/src/typing.nit +++ b/src/typing.nit @@ -696,6 +696,8 @@ redef class AVarReassignExpr var readtype = v.get_variable(self, variable) if readtype == null then return + read_type = readtype + var writetype = variable.declared_type if writetype == null then return diff --git a/tests/base_reassign_test.nit b/tests/base_reassign_test.nit new file mode 100644 index 0000000..d01302c --- /dev/null +++ b/tests/base_reassign_test.nit @@ -0,0 +1,19 @@ +# 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 x +x = 1 +x += 1 +x.output diff --git a/tests/sav/base_reassign_test.res b/tests/sav/base_reassign_test.res new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/tests/sav/base_reassign_test.res @@ -0,0 +1 @@ +2