Don't allow declaring void variables.
authorDavid Anderson <dvander@alliedmods.net>
Mon Dec 24 16:43:22 2012 -0800 (2012-12-24)
changeset 237c77540a61905
parent 236 072f1114ea5d
child 238 e9bec7549c28
Don't allow declaring void variables.
src/Messages.tbl
src/compiler/CompileContext.cpp
src/compiler/NameBinding.cpp
src/compiler/SemanticAnalysis.cpp
tests/basic/decl-void.err
tests/basic/decl-void.sp
     1.1 --- a/src/Messages.tbl	Mon Dec 24 16:09:13 2012 -0800
     1.2 +++ b/src/Messages.tbl	Mon Dec 24 16:43:22 2012 -0800
     1.3 @@ -54,6 +54,7 @@
     1.4  MSG(MissingReturnValue,             SyntaxError,            "function must return a value")
     1.5  MSG(NotAllPathsReturnValue,         SyntaxError,            "not all paths through function return a value")
     1.6  MSG(UsedVoidReturn,                 SyntaxError,            "value returned, but function is void")
     1.7 +MSG(CannotDeclareVoid,              TypeError,              "cannot declare void variables")
     1.8  MSG(FunctionDoesNotReturnValue,     SyntaxError,            "cannot use the result of a function with no return value")
     1.9  MSG(IdentifierNotFound,             SyntaxError,            "identifier '%s' could not be found")
    1.10  MSG(TypeMismatchDuringInvoke,       TypeError,              "incoming type '%s' does not match signature type '%s'")
     2.1 --- a/src/compiler/CompileContext.cpp	Mon Dec 24 16:09:13 2012 -0800
     2.2 +++ b/src/compiler/CompileContext.cpp	Mon Dec 24 16:43:22 2012 -0800
     2.3 @@ -247,6 +247,9 @@
     2.4              assert(false);
     2.5      }
     2.6  
     2.7 +    if (failures_)
     2.8 +        return false;
     2.9 +
    2.10      return true;
    2.11  }
    2.12  
     3.1 --- a/src/compiler/NameBinding.cpp	Mon Dec 24 16:09:13 2012 -0800
     3.2 +++ b/src/compiler/NameBinding.cpp	Mon Dec 24 16:43:22 2012 -0800
     3.3 @@ -861,6 +861,11 @@
     3.4                      if ((type = buildArrayType(type, dims, param->dims()->length())) == NULL)
     3.5                          return false;
     3.6                  }
     3.7 +
     3.8 +                if (ArrayType::cast(type)->innermost()->isVoid()) {
     3.9 +                    cc_.reportError(param->type()->pos(), Message_CannotDeclareVoid);
    3.10 +                    return false;
    3.11 +                }
    3.12              }
    3.13  
    3.14              if (param->reference()) {
    3.15 @@ -872,6 +877,11 @@
    3.16                      return false;
    3.17              }
    3.18  
    3.19 +            if (type->isVoid()) {
    3.20 +                cc_.reportError(param->type()->pos(), Message_CannotDeclareVoid);
    3.21 +                return false;
    3.22 +            }
    3.23 +
    3.24              params->set(zone_, i, type);
    3.25              param->sym()->setType(type);
    3.26          }
     4.1 --- a/src/compiler/SemanticAnalysis.cpp	Mon Dec 24 16:09:13 2012 -0800
     4.2 +++ b/src/compiler/SemanticAnalysis.cpp	Mon Dec 24 16:43:22 2012 -0800
     4.3 @@ -431,6 +431,11 @@
     4.4  
     4.5      Local<Type> type(zone_, node->sym()->type());
     4.6  
     4.7 +    if (node->sym()->type()->isVoid()) {
     4.8 +        cc_.reportError(node->type()->pos(), Message_CannotDeclareVoid);
     4.9 +        return;
    4.10 +    }
    4.11 +
    4.12      if (node->initialization()) {
    4.13          HIR *hir = NULL;
    4.14  
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tests/basic/decl-void.err	Mon Dec 24 16:43:22 2012 -0800
     5.3 @@ -0,0 +1,1 @@
     5.4 +  line 1, col 4: expected token '<name>', got '<void>'
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tests/basic/decl-void.sp	Mon Dec 24 16:43:22 2012 -0800
     6.3 @@ -0,0 +1,2 @@
     6.4 +new void:x;
     6.5 +