The any type is now recognized as a type properly

This commit is contained in:
2023-06-19 23:16:46 +10:00
parent 2157b2f540
commit f6ec6a8c73
2 changed files with 14 additions and 1 deletions

View File

@@ -628,6 +628,14 @@ static Toy_Opcode castingPrefix(Toy_Parser* parser, Toy_ASTNode** nodeHandle) {
} }
break; break;
//BUGFIX: handle this here, and not in castingPrefix, so "any" can be recognized as a type properly
case TOY_TOKEN_ANY: {
Toy_Literal literal = TOY_TO_TYPE_LITERAL(TOY_LITERAL_ANY, false);
Toy_emitASTNodeLiteral(nodeHandle, literal);
Toy_freeLiteral(literal);
}
break;
default: default:
error(parser, parser->previous, "Unexpected token passed to casting precedence rule"); error(parser, parser->previous, "Unexpected token passed to casting precedence rule");
return TOY_OP_EOF; return TOY_OP_EOF;
@@ -940,7 +948,7 @@ ParseRule parseRules[] = { //must match the token types
{NULL, NULL, PREC_NONE},// TOKEN_DICTIONARY, {NULL, NULL, PREC_NONE},// TOKEN_DICTIONARY,
{NULL, NULL, PREC_NONE},// TOKEN_FUNCTION, {NULL, NULL, PREC_NONE},// TOKEN_FUNCTION,
{NULL, NULL, PREC_NONE},// TOKEN_OPAQUE, {NULL, NULL, PREC_NONE},// TOKEN_OPAQUE,
{NULL, NULL, PREC_NONE},// TOKEN_ANY, {castingPrefix, NULL, PREC_CALL},// TOKEN_ANY,
//keywords and reserved words //keywords and reserved words
{NULL, NULL, PREC_NONE},// TOKEN_AS, {NULL, NULL, PREC_NONE},// TOKEN_AS,

View File

@@ -22,4 +22,9 @@ var dict: complex = [
"third array": [7, 8, 9] "third array": [7, 8, 9]
]; ];
//check the any type is recognized as a type within an array
var a: [type] = [int, bool, any];
print "All good"; print "All good";