# HG changeset patch # User David Anderson # Date 1356396202 28800 # Node ID c77540a619055e3a8a8c9e9c1cadf644899b71ea # Parent 072f1114ea5ddc43db6da7cae6660cab220c8fbb Don't allow declaring void variables. diff -r 072f1114ea5d -r c77540a61905 src/Messages.tbl --- a/src/Messages.tbl Mon Dec 24 16:09:13 2012 -0800 +++ b/src/Messages.tbl Mon Dec 24 16:43:22 2012 -0800 @@ -54,6 +54,7 @@ MSG(MissingReturnValue, SyntaxError, "function must return a value") MSG(NotAllPathsReturnValue, SyntaxError, "not all paths through function return a value") MSG(UsedVoidReturn, SyntaxError, "value returned, but function is void") +MSG(CannotDeclareVoid, TypeError, "cannot declare void variables") MSG(FunctionDoesNotReturnValue, SyntaxError, "cannot use the result of a function with no return value") MSG(IdentifierNotFound, SyntaxError, "identifier '%s' could not be found") MSG(TypeMismatchDuringInvoke, TypeError, "incoming type '%s' does not match signature type '%s'") diff -r 072f1114ea5d -r c77540a61905 src/compiler/CompileContext.cpp --- a/src/compiler/CompileContext.cpp Mon Dec 24 16:09:13 2012 -0800 +++ b/src/compiler/CompileContext.cpp Mon Dec 24 16:43:22 2012 -0800 @@ -247,6 +247,9 @@ assert(false); } + if (failures_) + return false; + return true; } diff -r 072f1114ea5d -r c77540a61905 src/compiler/NameBinding.cpp --- a/src/compiler/NameBinding.cpp Mon Dec 24 16:09:13 2012 -0800 +++ b/src/compiler/NameBinding.cpp Mon Dec 24 16:43:22 2012 -0800 @@ -861,6 +861,11 @@ if ((type = buildArrayType(type, dims, param->dims()->length())) == NULL) return false; } + + if (ArrayType::cast(type)->innermost()->isVoid()) { + cc_.reportError(param->type()->pos(), Message_CannotDeclareVoid); + return false; + } } if (param->reference()) { @@ -872,6 +877,11 @@ return false; } + if (type->isVoid()) { + cc_.reportError(param->type()->pos(), Message_CannotDeclareVoid); + return false; + } + params->set(zone_, i, type); param->sym()->setType(type); } diff -r 072f1114ea5d -r c77540a61905 src/compiler/SemanticAnalysis.cpp --- a/src/compiler/SemanticAnalysis.cpp Mon Dec 24 16:09:13 2012 -0800 +++ b/src/compiler/SemanticAnalysis.cpp Mon Dec 24 16:43:22 2012 -0800 @@ -431,6 +431,11 @@ Local type(zone_, node->sym()->type()); + if (node->sym()->type()->isVoid()) { + cc_.reportError(node->type()->pos(), Message_CannotDeclareVoid); + return; + } + if (node->initialization()) { HIR *hir = NULL; diff -r 072f1114ea5d -r c77540a61905 tests/basic/decl-void.err --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/basic/decl-void.err Mon Dec 24 16:43:22 2012 -0800 @@ -0,0 +1,1 @@ + line 1, col 4: expected token '', got '' diff -r 072f1114ea5d -r c77540a61905 tests/basic/decl-void.sp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/basic/decl-void.sp Mon Dec 24 16:43:22 2012 -0800 @@ -0,0 +1,2 @@ +new void:x; +