syntax: untyped local variables are 'nullable Object'
authorJean Privat <jean@pryen.org>
Thu, 7 Jan 2010 19:57:02 +0000 (14:57 -0500)
committerJean Privat <jean@pryen.org>
Thu, 14 Jan 2010 16:43:41 +0000 (11:43 -0500)
This partially reverts commit 220823e713cef8915241679a614fbfb53ddaece0
"syntax: allow untyped variable declaration".

Signed-off-by: Jean Privat <jean@pryen.org>

src/syntax/control_flow.nit
src/syntax/icode_generation.nit
src/syntax/syntax_base.nit
src/syntax/typing.nit
tests/sav/base_var_untyped_alt2.sav
tests/sav/base_var_untyped_alt4.sav
tests/sav/base_var_untyped_alt5.sav
tests/sav/base_var_untyped_alt6.sav
tests/sav/base_var_untyped_alt8.sav

index 6db1444..2c7e691 100644 (file)
@@ -53,8 +53,6 @@ abstract class VariableContext
        do
                if v.must_be_set and not is_set(v) then
                        _visitor.error(n, "Error: variable '{v}' is possibly unset.")
-               else if v.is_typed and stype(v) == null then
-                       _visitor.error(n, "Error: variable '{v}' is untyped.")
                end
        end
 
index af61111..15255a7 100644 (file)
@@ -58,9 +58,7 @@ special ICodeBuilder
                if _variables.has_key(v) then
                        return _variables[v]
                else
-                       var t = v.stype
-                       if t == null then t = visitor.type_object.as_nullable
-                       var reg = new_register(t)
+                       var reg = new_register(v.stype.as(not null))
                        _variables[v] = reg
                        return reg
                end
index 13e1372..512ccf4 100644 (file)
@@ -229,12 +229,7 @@ abstract class Variable
        # Declaration AST node
        readable var _decl: nullable ANode
 
-       # Is the variable correcly declared
-       # Return false if typed was not yet computed or
-       # if an error occured during the typing computation
-       fun is_typed: Bool do return _stype != null
-
-       # The declaration static type of the variable
+       # Static type
        readable writable var _stype: nullable MMType
 
        redef fun to_s do return _name.to_s
index 840ed5e..97eb5f2 100644 (file)
@@ -136,9 +136,6 @@ special AbsSyntaxVisitor
        end
 end
 
-redef class VarVariable
-       redef readable var _is_typed: Bool = false
-end
 
 ###############################################################################
 
@@ -373,9 +370,10 @@ redef class AVardeclExpr
                        end
                else if ne != null then
                        if not v.check_expr(ne) then return
-                       va.stype = n_expr.stype
+                       va.stype = ne.stype
+               else
+                       va.stype = v.type_object.as_nullable
                end
-               va._is_typed = true
                _is_typed = true
        end
 end
index a5c54ef..e1c0aa1 100644 (file)
@@ -1 +1,6 @@
-alt/base_var_untyped_alt2.nit:42,1--2: Error: variable 'b2' is untyped.
+10
+20
+true
+30
+4
+40
index a18278f..c5a455f 100644 (file)
@@ -1 +1 @@
-alt/base_var_untyped_alt4.nit:44,1--7: Error: variable 'b2' is untyped.
+alt/base_var_untyped_alt4.nit:44,1--7: Error: Method '+' doesn't exists in nullable Object.
index 892ac1b..2072129 100644 (file)
@@ -1 +1 @@
-alt/base_var_untyped_alt5.nit:49,6--7: Error: variable 'b2' is untyped.
+alt/base_var_untyped_alt5.nit:51,3--6: Error: Method '*' doesn't exists in nullable Object.
index 798387e..dd3223c 100644 (file)
@@ -1 +1,2 @@
 alt/base_var_untyped_alt6.nit:50,6--7: Error: variable 'b3' is possibly unset.
+alt/base_var_untyped_alt6.nit:51,3--6: Error: Method '*' doesn't exists in nullable Object.
index b4cd0ba..1eeaef7 100644 (file)
@@ -1,2 +1 @@
 alt/base_var_untyped_alt8.nit:57,5--8: Error: Method or variable 'fail' unknown in Sys.
-alt/base_var_untyped_alt8.nit:58,1: Error: variable 'd' is untyped.