diff --git a/compiler/TypeCheck.jrag b/compiler/TypeCheck.jrag index 1536ee8ba223a5582710fef12e9a596d6ddef76b..747d830e304d4995b97cd256884a5a0456d2545b 100644 --- a/compiler/TypeCheck.jrag +++ b/compiler/TypeCheck.jrag @@ -1,29 +1,36 @@ aspect TypeCheck { public void ASTNode.typeCheck() { - for (int i = 0; i < getNumChild(); i++) { - getChild(i).typeCheck(); - } + // calls to the different type checks to be performed + nullTypeCheck(); } + +// void is not allowed as a field in a struct or an array element syn boolean Type.isNull(); eq Type.isNull() = false; eq VoidType.isNull() = true; + eq UserType.isNull() = decl().isNull(); + + syn boolean TypeDecl.isNull(); + eq TypeDecl.isNull() = getType().isNull(); + public void ASTNode.nullTypeCheck() {} + public void Field.nullTypeCheck() { if(getType().isNull()) { - error(getName() + ": fields cannot be of type void"); + error("field " + getName() + " may not be of type void"); } } public void ParseArrayType.nullTypeCheck() { if(getType().isNull()) { - error("array elements cannot be of type void"); + error("array elements may not be of type void"); } } public void ArrayType.nullTypeCheck() { if(getType().isNull()) { - error("array elements cannot be of type void"); + error("array elements may not be of type void"); } } } diff --git a/examples/simple/simple.lc b/examples/simple/simple.lc index c3725ac5b1ed9d68aa83550089f5f5bddf571ac1..f25295d4d5e45c6fd9cb703fea483ab949281405 100644 --- a/examples/simple/simple.lc +++ b/examples/simple/simple.lc @@ -29,3 +29,14 @@ sample struct { typedef void avoid; sample avoid doavoid; + +// examples of errors: void may not be used +// in structs or arrays +// +// sample struct { +// int a; +// avoid error; +//} foo; +// +//sample void error2[2] ; +//sample avoid error3[_];