syntax: allow untyped variable declaration
[nit.git] / src / syntax / control_flow.nit
index 4cd879b..dd3ca06 100644 (file)
@@ -36,6 +36,10 @@ abstract class VariableContext
        # Register a new variable with its name
        fun add(v: Variable)
        do
+               var old_var = self[v.name]
+               if old_var != null then
+                       _visitor.error(v.decl, "Error: '{v}' already defined at {old_var.decl.location.relative_to(v.decl.location)}.")
+               end
                _dico[v.name] = v
                _all_variables.add(v)
        end
@@ -49,6 +53,8 @@ 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