nitg: Corrected bug when creating a new AVarExpr, uses the last inferred type instead...
authorLucas Bajolet <r4pass@hotmail.com>
Tue, 11 Feb 2014 21:10:40 +0000 (16:10 -0500)
committerLucas Bajolet <r4pass@hotmail.com>
Tue, 11 Feb 2014 21:10:40 +0000 (16:10 -0500)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

src/astbuilder.nit
src/transform.nit
src/typing.nit
tests/base_reassign_test.nit [new file with mode: 0644]
tests/sav/base_reassign_test.res [new file with mode: 0644]

index e6182a0..0db3b4d 100644 (file)
@@ -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
 
index f3200fa..4ec6635 100644 (file)
@@ -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)
 
index 527f694..c760c74 100644 (file)
@@ -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 (file)
index 0000000..d01302c
--- /dev/null
@@ -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 (file)
index 0000000..0cfbf08
--- /dev/null
@@ -0,0 +1 @@
+2