| author | |
| committer | |
| log | eff3530dfab5ecb4e480e0516ed57a8f564543f5 |
| tree | 6d407f8f334e1910e0ae6ea16190aa9c3e5de016 |
| parent | 44ae891bd79cc8b2f9040a39c176317ebf4a4ef8 |
closes #7798 files changed, 116 insertions(+), 154 deletions(-)
doc/langref.html.in+3-3| ... | @@ -5733,19 +5733,19 @@ UseDecl = "use" Expression ";" | ... | @@ -5733,19 +5733,19 @@ UseDecl = "use" Expression ";" |
| 5733 | 5733 | ||
| 5734 | ExternDecl = "extern" option(String) (FnProto | VariableDeclaration) ";" | 5734 | ExternDecl = "extern" option(String) (FnProto | VariableDeclaration) ";" |
| 5735 | 5735 | ||
| 5736 | FnProto = option("nakedcc" | "stdcallcc" | "extern" | ("async" option("(" Expression ")"))) "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("!") TypeExpr | 5736 | FnProto = option("nakedcc" | "stdcallcc" | "extern" | ("async" option("(" Expression ")"))) "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("!") (TypeExpr | "var") |
| 5737 | 5737 | ||
| 5738 | FnDef = option("inline" | "export") FnProto Block | 5738 | FnDef = option("inline" | "export") FnProto Block |
| 5739 | 5739 | ||
| 5740 | ParamDeclList = "(" list(ParamDecl, ",") ")" | 5740 | ParamDeclList = "(" list(ParamDecl, ",") ")" |
| 5741 | 5741 | ||
| 5742 | ParamDecl = option("noalias" | "comptime") option(Symbol ":") (TypeExpr | "...") | 5742 | ParamDecl = option("noalias" | "comptime") option(Symbol ":") (TypeExpr | "var" | "...") |
| 5743 | 5743 | ||
| 5744 | Block = option(Symbol ":") "{" many(Statement) "}" | 5744 | Block = option(Symbol ":") "{" many(Statement) "}" |
| 5745 | 5745 | ||
| 5746 | Statement = LocalVarDecl ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";" | 5746 | Statement = LocalVarDecl ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";" |
| 5747 | 5747 | ||
| 5748 | TypeExpr = ErrorSetExpr | "var" | 5748 | TypeExpr = ErrorSetExpr |
| 5749 | 5749 | ||
| 5750 | ErrorSetExpr = (PrefixOpExpression "!" PrefixOpExpression) | PrefixOpExpression | 5750 | ErrorSetExpr = (PrefixOpExpression "!" PrefixOpExpression) | PrefixOpExpression |
| 5751 | 5751 |
src/all_types.hpp+3-6| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | #include "bigint.hpp" | 16 | #include "bigint.hpp" |
| 17 | #include "bigfloat.hpp" | 17 | #include "bigfloat.hpp" |
| 18 | #include "target.hpp" | 18 | #include "target.hpp" |
| 19 | #include "tokenizer.hpp" | ||
| 19 | 20 | ||
| 20 | struct AstNode; | 21 | struct AstNode; |
| 21 | struct ImportTableEntry; | 22 | struct ImportTableEntry; |
| ... | @@ -399,7 +400,6 @@ enum NodeType { | ... | @@ -399,7 +400,6 @@ enum NodeType { |
| 399 | NodeTypeStructValueField, | 400 | NodeTypeStructValueField, |
| 400 | NodeTypeArrayType, | 401 | NodeTypeArrayType, |
| 401 | NodeTypeErrorType, | 402 | NodeTypeErrorType, |
| 402 | NodeTypeVarLiteral, | ||
| 403 | NodeTypeIfErrorExpr, | 403 | NodeTypeIfErrorExpr, |
| 404 | NodeTypeTestExpr, | 404 | NodeTypeTestExpr, |
| 405 | NodeTypeErrorSetDecl, | 405 | NodeTypeErrorSetDecl, |
| ... | @@ -427,6 +427,7 @@ struct AstNodeFnProto { | ... | @@ -427,6 +427,7 @@ struct AstNodeFnProto { |
| 427 | Buf *name; | 427 | Buf *name; |
| 428 | ZigList<AstNode *> params; | 428 | ZigList<AstNode *> params; |
| 429 | AstNode *return_type; | 429 | AstNode *return_type; |
| 430 | Token *return_var_token; | ||
| 430 | bool is_var_args; | 431 | bool is_var_args; |
| 431 | bool is_extern; | 432 | bool is_extern; |
| 432 | bool is_export; | 433 | bool is_export; |
| ... | @@ -456,6 +457,7 @@ struct AstNodeFnDecl { | ... | @@ -456,6 +457,7 @@ struct AstNodeFnDecl { |
| 456 | struct AstNodeParamDecl { | 457 | struct AstNodeParamDecl { |
| 457 | Buf *name; | 458 | Buf *name; |
| 458 | AstNode *type; | 459 | AstNode *type; |
| 460 | Token *var_token; | ||
| 459 | bool is_noalias; | 461 | bool is_noalias; |
| 460 | bool is_inline; | 462 | bool is_inline; |
| 461 | bool is_var_args; | 463 | bool is_var_args; |
| ... | @@ -866,9 +868,6 @@ struct AstNodeUnreachableExpr { | ... | @@ -866,9 +868,6 @@ struct AstNodeUnreachableExpr { |
| 866 | struct AstNodeErrorType { | 868 | struct AstNodeErrorType { |
| 867 | }; | 869 | }; |
| 868 | 870 | ||
| 869 | struct AstNodeVarLiteral { | ||
| 870 | }; | ||
| 871 | |||
| 872 | struct AstNodeAwaitExpr { | 871 | struct AstNodeAwaitExpr { |
| 873 | AstNode *expr; | 872 | AstNode *expr; |
| 874 | }; | 873 | }; |
| ... | @@ -933,7 +932,6 @@ struct AstNode { | ... | @@ -933,7 +932,6 @@ struct AstNode { |
| 933 | AstNodeUnreachableExpr unreachable_expr; | 932 | AstNodeUnreachableExpr unreachable_expr; |
| 934 | AstNodeArrayType array_type; | 933 | AstNodeArrayType array_type; |
| 935 | AstNodeErrorType error_type; | 934 | AstNodeErrorType error_type; |
| 936 | AstNodeVarLiteral var_literal; | ||
| 937 | AstNodeErrorSetDecl err_set_decl; | 935 | AstNodeErrorSetDecl err_set_decl; |
| 938 | AstNodeCancelExpr cancel_expr; | 936 | AstNodeCancelExpr cancel_expr; |
| 939 | AstNodeResumeExpr resume_expr; | 937 | AstNodeResumeExpr resume_expr; |
| ... | @@ -1134,7 +1132,6 @@ struct TypeTableEntryPromise { | ... | @@ -1134,7 +1132,6 @@ struct TypeTableEntryPromise { |
| 1134 | 1132 | ||
| 1135 | enum TypeTableEntryId { | 1133 | enum TypeTableEntryId { |
| 1136 | TypeTableEntryIdInvalid, | 1134 | TypeTableEntryIdInvalid, |
| 1137 | TypeTableEntryIdVar, | ||
| 1138 | TypeTableEntryIdMetaType, | 1135 | TypeTableEntryIdMetaType, |
| 1139 | TypeTableEntryIdVoid, | 1136 | TypeTableEntryIdVoid, |
| 1140 | TypeTableEntryIdBool, | 1137 | TypeTableEntryIdBool, |
src/analyze.cpp+18-28| ... | @@ -200,7 +200,6 @@ static uint8_t bits_needed_for_unsigned(uint64_t x) { | ... | @@ -200,7 +200,6 @@ static uint8_t bits_needed_for_unsigned(uint64_t x) { |
| 200 | bool type_is_complete(TypeTableEntry *type_entry) { | 200 | bool type_is_complete(TypeTableEntry *type_entry) { |
| 201 | switch (type_entry->id) { | 201 | switch (type_entry->id) { |
| 202 | case TypeTableEntryIdInvalid: | 202 | case TypeTableEntryIdInvalid: |
| 203 | case TypeTableEntryIdVar: | ||
| 204 | zig_unreachable(); | 203 | zig_unreachable(); |
| 205 | case TypeTableEntryIdStruct: | 204 | case TypeTableEntryIdStruct: |
| 206 | return type_entry->data.structure.complete; | 205 | return type_entry->data.structure.complete; |
| ... | @@ -239,7 +238,6 @@ bool type_is_complete(TypeTableEntry *type_entry) { | ... | @@ -239,7 +238,6 @@ bool type_is_complete(TypeTableEntry *type_entry) { |
| 239 | bool type_has_zero_bits_known(TypeTableEntry *type_entry) { | 238 | bool type_has_zero_bits_known(TypeTableEntry *type_entry) { |
| 240 | switch (type_entry->id) { | 239 | switch (type_entry->id) { |
| 241 | case TypeTableEntryIdInvalid: | 240 | case TypeTableEntryIdInvalid: |
| 242 | case TypeTableEntryIdVar: | ||
| 243 | zig_unreachable(); | 241 | zig_unreachable(); |
| 244 | case TypeTableEntryIdStruct: | 242 | case TypeTableEntryIdStruct: |
| 245 | return type_entry->data.structure.zero_bits_known; | 243 | return type_entry->data.structure.zero_bits_known; |
| ... | @@ -1281,7 +1279,6 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf ** | ... | @@ -1281,7 +1279,6 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf ** |
| 1281 | static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) { | 1279 | static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) { |
| 1282 | switch (type_entry->id) { | 1280 | switch (type_entry->id) { |
| 1283 | case TypeTableEntryIdInvalid: | 1281 | case TypeTableEntryIdInvalid: |
| 1284 | case TypeTableEntryIdVar: | ||
| 1285 | zig_unreachable(); | 1282 | zig_unreachable(); |
| 1286 | case TypeTableEntryIdMetaType: | 1283 | case TypeTableEntryIdMetaType: |
| 1287 | case TypeTableEntryIdUnreachable: | 1284 | case TypeTableEntryIdUnreachable: |
| ... | @@ -1324,7 +1321,6 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) { | ... | @@ -1324,7 +1321,6 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) { |
| 1324 | static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) { | 1321 | static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) { |
| 1325 | switch (type_entry->id) { | 1322 | switch (type_entry->id) { |
| 1326 | case TypeTableEntryIdInvalid: | 1323 | case TypeTableEntryIdInvalid: |
| 1327 | case TypeTableEntryIdVar: | ||
| 1328 | zig_unreachable(); | 1324 | zig_unreachable(); |
| 1329 | case TypeTableEntryIdMetaType: | 1325 | case TypeTableEntryIdMetaType: |
| 1330 | case TypeTableEntryIdNumLitFloat: | 1326 | case TypeTableEntryIdNumLitFloat: |
| ... | @@ -1428,6 +1424,14 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c | ... | @@ -1428,6 +1424,14 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1428 | calling_convention_name(fn_type_id.cc))); | 1424 | calling_convention_name(fn_type_id.cc))); |
| 1429 | return g->builtin_types.entry_invalid; | 1425 | return g->builtin_types.entry_invalid; |
| 1430 | } | 1426 | } |
| 1427 | } else if (param_node->data.param_decl.var_token != nullptr) { | ||
| 1428 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { | ||
| 1429 | add_node_error(g, param_node->data.param_decl.type, | ||
| 1430 | buf_sprintf("parameter of type 'var' not allowed in function with calling convention '%s'", | ||
| 1431 | calling_convention_name(fn_type_id.cc))); | ||
| 1432 | return g->builtin_types.entry_invalid; | ||
| 1433 | } | ||
| 1434 | return get_generic_fn_type(g, &fn_type_id); | ||
| 1431 | } | 1435 | } |
| 1432 | 1436 | ||
| 1433 | TypeTableEntry *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type); | 1437 | TypeTableEntry *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type); |
| ... | @@ -1463,14 +1467,6 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c | ... | @@ -1463,14 +1467,6 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1463 | add_node_error(g, param_node->data.param_decl.type, | 1467 | add_node_error(g, param_node->data.param_decl.type, |
| 1464 | buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name))); | 1468 | buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name))); |
| 1465 | return g->builtin_types.entry_invalid; | 1469 | return g->builtin_types.entry_invalid; |
| 1466 | case TypeTableEntryIdVar: | ||
| 1467 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { | ||
| 1468 | add_node_error(g, param_node->data.param_decl.type, | ||
| 1469 | buf_sprintf("parameter of type 'var' not allowed in function with calling convention '%s'", | ||
| 1470 | calling_convention_name(fn_type_id.cc))); | ||
| 1471 | return g->builtin_types.entry_invalid; | ||
| 1472 | } | ||
| 1473 | return get_generic_fn_type(g, &fn_type_id); | ||
| 1474 | case TypeTableEntryIdNumLitFloat: | 1470 | case TypeTableEntryIdNumLitFloat: |
| 1475 | case TypeTableEntryIdNumLitInt: | 1471 | case TypeTableEntryIdNumLitInt: |
| 1476 | case TypeTableEntryIdNamespace: | 1472 | case TypeTableEntryIdNamespace: |
| ... | @@ -1527,6 +1523,16 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c | ... | @@ -1527,6 +1523,16 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1527 | fn_type_id.return_type = specified_return_type; | 1523 | fn_type_id.return_type = specified_return_type; |
| 1528 | } | 1524 | } |
| 1529 | 1525 | ||
| 1526 | if (fn_proto->return_var_token != nullptr) { | ||
| 1527 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { | ||
| 1528 | add_node_error(g, fn_proto->return_type, | ||
| 1529 | buf_sprintf("return type 'var' not allowed in function with calling convention '%s'", | ||
| 1530 | calling_convention_name(fn_type_id.cc))); | ||
| 1531 | return g->builtin_types.entry_invalid; | ||
| 1532 | } | ||
| 1533 | return get_generic_fn_type(g, &fn_type_id); | ||
| 1534 | } | ||
| 1535 | |||
| 1530 | if (!calling_convention_allows_zig_types(fn_type_id.cc) && !type_allowed_in_extern(g, fn_type_id.return_type)) { | 1536 | if (!calling_convention_allows_zig_types(fn_type_id.cc) && !type_allowed_in_extern(g, fn_type_id.return_type)) { |
| 1531 | add_node_error(g, fn_proto->return_type, | 1537 | add_node_error(g, fn_proto->return_type, |
| 1532 | buf_sprintf("return type '%s' not allowed in function with calling convention '%s'", | 1538 | buf_sprintf("return type '%s' not allowed in function with calling convention '%s'", |
| ... | @@ -1552,7 +1558,6 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c | ... | @@ -1552,7 +1558,6 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1552 | case TypeTableEntryIdNamespace: | 1558 | case TypeTableEntryIdNamespace: |
| 1553 | case TypeTableEntryIdBlock: | 1559 | case TypeTableEntryIdBlock: |
| 1554 | case TypeTableEntryIdBoundFn: | 1560 | case TypeTableEntryIdBoundFn: |
| 1555 | case TypeTableEntryIdVar: | ||
| 1556 | case TypeTableEntryIdMetaType: | 1561 | case TypeTableEntryIdMetaType: |
| 1557 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { | 1562 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1558 | add_node_error(g, fn_proto->return_type, | 1563 | add_node_error(g, fn_proto->return_type, |
| ... | @@ -3226,7 +3231,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { | ... | @@ -3226,7 +3231,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { |
| 3226 | case NodeTypeStructValueField: | 3231 | case NodeTypeStructValueField: |
| 3227 | case NodeTypeArrayType: | 3232 | case NodeTypeArrayType: |
| 3228 | case NodeTypeErrorType: | 3233 | case NodeTypeErrorType: |
| 3229 | case NodeTypeVarLiteral: | ||
| 3230 | case NodeTypeIfErrorExpr: | 3234 | case NodeTypeIfErrorExpr: |
| 3231 | case NodeTypeTestExpr: | 3235 | case NodeTypeTestExpr: |
| 3232 | case NodeTypeErrorSetDecl: | 3236 | case NodeTypeErrorSetDecl: |
| ... | @@ -3262,7 +3266,6 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt | ... | @@ -3262,7 +3266,6 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt |
| 3262 | case TypeTableEntryIdInvalid: | 3266 | case TypeTableEntryIdInvalid: |
| 3263 | return g->builtin_types.entry_invalid; | 3267 | return g->builtin_types.entry_invalid; |
| 3264 | case TypeTableEntryIdUnreachable: | 3268 | case TypeTableEntryIdUnreachable: |
| 3265 | case TypeTableEntryIdVar: | ||
| 3266 | case TypeTableEntryIdNumLitFloat: | 3269 | case TypeTableEntryIdNumLitFloat: |
| 3267 | case TypeTableEntryIdNumLitInt: | 3270 | case TypeTableEntryIdNumLitInt: |
| 3268 | case TypeTableEntryIdUndefLit: | 3271 | case TypeTableEntryIdUndefLit: |
| ... | @@ -3641,7 +3644,6 @@ TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *t | ... | @@ -3641,7 +3644,6 @@ TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *t |
| 3641 | static bool is_container(TypeTableEntry *type_entry) { | 3644 | static bool is_container(TypeTableEntry *type_entry) { |
| 3642 | switch (type_entry->id) { | 3645 | switch (type_entry->id) { |
| 3643 | case TypeTableEntryIdInvalid: | 3646 | case TypeTableEntryIdInvalid: |
| 3644 | case TypeTableEntryIdVar: | ||
| 3645 | zig_unreachable(); | 3647 | zig_unreachable(); |
| 3646 | case TypeTableEntryIdStruct: | 3648 | case TypeTableEntryIdStruct: |
| 3647 | case TypeTableEntryIdEnum: | 3649 | case TypeTableEntryIdEnum: |
| ... | @@ -3716,7 +3718,6 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) { | ... | @@ -3716,7 +3718,6 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) { |
| 3716 | case TypeTableEntryIdBlock: | 3718 | case TypeTableEntryIdBlock: |
| 3717 | case TypeTableEntryIdBoundFn: | 3719 | case TypeTableEntryIdBoundFn: |
| 3718 | case TypeTableEntryIdInvalid: | 3720 | case TypeTableEntryIdInvalid: |
| 3719 | case TypeTableEntryIdVar: | ||
| 3720 | case TypeTableEntryIdArgTuple: | 3721 | case TypeTableEntryIdArgTuple: |
| 3721 | case TypeTableEntryIdOpaque: | 3722 | case TypeTableEntryIdOpaque: |
| 3722 | case TypeTableEntryIdPromise: | 3723 | case TypeTableEntryIdPromise: |
| ... | @@ -4216,7 +4217,6 @@ bool handle_is_ptr(TypeTableEntry *type_entry) { | ... | @@ -4216,7 +4217,6 @@ bool handle_is_ptr(TypeTableEntry *type_entry) { |
| 4216 | case TypeTableEntryIdNamespace: | 4217 | case TypeTableEntryIdNamespace: |
| 4217 | case TypeTableEntryIdBlock: | 4218 | case TypeTableEntryIdBlock: |
| 4218 | case TypeTableEntryIdBoundFn: | 4219 | case TypeTableEntryIdBoundFn: |
| 4219 | case TypeTableEntryIdVar: | ||
| 4220 | case TypeTableEntryIdArgTuple: | 4220 | case TypeTableEntryIdArgTuple: |
| 4221 | case TypeTableEntryIdOpaque: | 4221 | case TypeTableEntryIdOpaque: |
| 4222 | zig_unreachable(); | 4222 | zig_unreachable(); |
| ... | @@ -4515,7 +4515,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { | ... | @@ -4515,7 +4515,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { |
| 4515 | case TypeTableEntryIdBoundFn: | 4515 | case TypeTableEntryIdBoundFn: |
| 4516 | case TypeTableEntryIdInvalid: | 4516 | case TypeTableEntryIdInvalid: |
| 4517 | case TypeTableEntryIdUnreachable: | 4517 | case TypeTableEntryIdUnreachable: |
| 4518 | case TypeTableEntryIdVar: | ||
| 4519 | zig_unreachable(); | 4518 | zig_unreachable(); |
| 4520 | } | 4519 | } |
| 4521 | zig_unreachable(); | 4520 | zig_unreachable(); |
| ... | @@ -4613,7 +4612,6 @@ bool type_has_bits(TypeTableEntry *type_entry) { | ... | @@ -4613,7 +4612,6 @@ bool type_has_bits(TypeTableEntry *type_entry) { |
| 4613 | bool type_requires_comptime(TypeTableEntry *type_entry) { | 4612 | bool type_requires_comptime(TypeTableEntry *type_entry) { |
| 4614 | switch (type_entry->id) { | 4613 | switch (type_entry->id) { |
| 4615 | case TypeTableEntryIdInvalid: | 4614 | case TypeTableEntryIdInvalid: |
| 4616 | case TypeTableEntryIdVar: | ||
| 4617 | case TypeTableEntryIdOpaque: | 4615 | case TypeTableEntryIdOpaque: |
| 4618 | zig_unreachable(); | 4616 | zig_unreachable(); |
| 4619 | case TypeTableEntryIdNumLitFloat: | 4617 | case TypeTableEntryIdNumLitFloat: |
| ... | @@ -5109,7 +5107,6 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { | ... | @@ -5109,7 +5107,6 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { |
| 5109 | case TypeTableEntryIdBoundFn: | 5107 | case TypeTableEntryIdBoundFn: |
| 5110 | case TypeTableEntryIdInvalid: | 5108 | case TypeTableEntryIdInvalid: |
| 5111 | case TypeTableEntryIdUnreachable: | 5109 | case TypeTableEntryIdUnreachable: |
| 5112 | case TypeTableEntryIdVar: | ||
| 5113 | case TypeTableEntryIdPromise: | 5110 | case TypeTableEntryIdPromise: |
| 5114 | zig_unreachable(); | 5111 | zig_unreachable(); |
| 5115 | } | 5112 | } |
| ... | @@ -5189,9 +5186,6 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { | ... | @@ -5189,9 +5186,6 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { |
| 5189 | case TypeTableEntryIdInvalid: | 5186 | case TypeTableEntryIdInvalid: |
| 5190 | buf_appendf(buf, "(invalid)"); | 5187 | buf_appendf(buf, "(invalid)"); |
| 5191 | return; | 5188 | return; |
| 5192 | case TypeTableEntryIdVar: | ||
| 5193 | buf_appendf(buf, "(var)"); | ||
| 5194 | return; | ||
| 5195 | case TypeTableEntryIdVoid: | 5189 | case TypeTableEntryIdVoid: |
| 5196 | buf_appendf(buf, "{}"); | 5190 | buf_appendf(buf, "{}"); |
| 5197 | return; | 5191 | return; |
| ... | @@ -5427,7 +5421,6 @@ TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) | ... | @@ -5427,7 +5421,6 @@ TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) |
| 5427 | uint32_t type_id_hash(TypeId x) { | 5421 | uint32_t type_id_hash(TypeId x) { |
| 5428 | switch (x.id) { | 5422 | switch (x.id) { |
| 5429 | case TypeTableEntryIdInvalid: | 5423 | case TypeTableEntryIdInvalid: |
| 5430 | case TypeTableEntryIdVar: | ||
| 5431 | case TypeTableEntryIdOpaque: | 5424 | case TypeTableEntryIdOpaque: |
| 5432 | case TypeTableEntryIdMetaType: | 5425 | case TypeTableEntryIdMetaType: |
| 5433 | case TypeTableEntryIdVoid: | 5426 | case TypeTableEntryIdVoid: |
| ... | @@ -5474,7 +5467,6 @@ bool type_id_eql(TypeId a, TypeId b) { | ... | @@ -5474,7 +5467,6 @@ bool type_id_eql(TypeId a, TypeId b) { |
| 5474 | return false; | 5467 | return false; |
| 5475 | switch (a.id) { | 5468 | switch (a.id) { |
| 5476 | case TypeTableEntryIdInvalid: | 5469 | case TypeTableEntryIdInvalid: |
| 5477 | case TypeTableEntryIdVar: | ||
| 5478 | case TypeTableEntryIdMetaType: | 5470 | case TypeTableEntryIdMetaType: |
| 5479 | case TypeTableEntryIdVoid: | 5471 | case TypeTableEntryIdVoid: |
| 5480 | case TypeTableEntryIdBool: | 5472 | case TypeTableEntryIdBool: |
| ... | @@ -5629,7 +5621,6 @@ size_t type_id_len() { | ... | @@ -5629,7 +5621,6 @@ size_t type_id_len() { |
| 5629 | size_t type_id_index(TypeTableEntryId id) { | 5621 | size_t type_id_index(TypeTableEntryId id) { |
| 5630 | switch (id) { | 5622 | switch (id) { |
| 5631 | case TypeTableEntryIdInvalid: | 5623 | case TypeTableEntryIdInvalid: |
| 5632 | case TypeTableEntryIdVar: | ||
| 5633 | zig_unreachable(); | 5624 | zig_unreachable(); |
| 5634 | case TypeTableEntryIdMetaType: | 5625 | case TypeTableEntryIdMetaType: |
| 5635 | return 0; | 5626 | return 0; |
| ... | @@ -5688,7 +5679,6 @@ size_t type_id_index(TypeTableEntryId id) { | ... | @@ -5688,7 +5679,6 @@ size_t type_id_index(TypeTableEntryId id) { |
| 5688 | const char *type_id_name(TypeTableEntryId id) { | 5679 | const char *type_id_name(TypeTableEntryId id) { |
| 5689 | switch (id) { | 5680 | switch (id) { |
| 5690 | case TypeTableEntryIdInvalid: | 5681 | case TypeTableEntryIdInvalid: |
| 5691 | case TypeTableEntryIdVar: | ||
| 5692 | zig_unreachable(); | 5682 | zig_unreachable(); |
| 5693 | case TypeTableEntryIdMetaType: | 5683 | case TypeTableEntryIdMetaType: |
| 5694 | return "Type"; | 5684 | return "Type"; |
src/ast_render.cpp+12-11| ... | @@ -236,8 +236,6 @@ static const char *node_type_str(NodeType node_type) { | ... | @@ -236,8 +236,6 @@ static const char *node_type_str(NodeType node_type) { |
| 236 | return "ArrayType"; | 236 | return "ArrayType"; |
| 237 | case NodeTypeErrorType: | 237 | case NodeTypeErrorType: |
| 238 | return "ErrorType"; | 238 | return "ErrorType"; |
| 239 | case NodeTypeVarLiteral: | ||
| 240 | return "VarLiteral"; | ||
| 241 | case NodeTypeIfErrorExpr: | 239 | case NodeTypeIfErrorExpr: |
| 242 | return "IfErrorExpr"; | 240 | return "IfErrorExpr"; |
| 243 | case NodeTypeTestExpr: | 241 | case NodeTypeTestExpr: |
| ... | @@ -436,6 +434,8 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { | ... | @@ -436,6 +434,8 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 436 | } | 434 | } |
| 437 | if (param_decl->data.param_decl.is_var_args) { | 435 | if (param_decl->data.param_decl.is_var_args) { |
| 438 | fprintf(ar->f, "..."); | 436 | fprintf(ar->f, "..."); |
| 437 | } else if (param_decl->data.param_decl.var_token != nullptr) { | ||
| 438 | fprintf(ar->f, "var"); | ||
| 439 | } else { | 439 | } else { |
| 440 | render_node_grouped(ar, param_decl->data.param_decl.type); | 440 | render_node_grouped(ar, param_decl->data.param_decl.type); |
| 441 | } | 441 | } |
| ... | @@ -456,13 +456,17 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { | ... | @@ -456,13 +456,17 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 456 | fprintf(ar->f, ")"); | 456 | fprintf(ar->f, ")"); |
| 457 | } | 457 | } |
| 458 | 458 | ||
| 459 | AstNode *return_type_node = node->data.fn_proto.return_type; | 459 | if (node->data.fn_proto.return_var_token != nullptr) { |
| 460 | assert(return_type_node != nullptr); | 460 | fprintf(ar->f, "var"); |
| 461 | fprintf(ar->f, " "); | 461 | } else { |
| 462 | if (node->data.fn_proto.auto_err_set) { | 462 | AstNode *return_type_node = node->data.fn_proto.return_type; |
| 463 | fprintf(ar->f, "!"); | 463 | assert(return_type_node != nullptr); |
| 464 | fprintf(ar->f, " "); | ||
| 465 | if (node->data.fn_proto.auto_err_set) { | ||
| 466 | fprintf(ar->f, "!"); | ||
| 467 | } | ||
| 468 | render_node_grouped(ar, return_type_node); | ||
| 464 | } | 469 | } |
| 465 | render_node_grouped(ar, return_type_node); | ||
| 466 | break; | 470 | break; |
| 467 | } | 471 | } |
| 468 | case NodeTypeFnDef: | 472 | case NodeTypeFnDef: |
| ... | @@ -768,9 +772,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { | ... | @@ -768,9 +772,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 768 | case NodeTypeErrorType: | 772 | case NodeTypeErrorType: |
| 769 | fprintf(ar->f, "error"); | 773 | fprintf(ar->f, "error"); |
| 770 | break; | 774 | break; |
| 771 | case NodeTypeVarLiteral: | ||
| 772 | fprintf(ar->f, "var"); | ||
| 773 | break; | ||
| 774 | case NodeTypeAsmExpr: | 775 | case NodeTypeAsmExpr: |
| 775 | { | 776 | { |
| 776 | AstNodeAsmExpr *asm_expr = &node->data.asm_expr; | 777 | AstNodeAsmExpr *asm_expr = &node->data.asm_expr; |
src/codegen.cpp-10| ... | @@ -4508,7 +4508,6 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con | ... | @@ -4508,7 +4508,6 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con |
| 4508 | assert(!type_entry->zero_bits); | 4508 | assert(!type_entry->zero_bits); |
| 4509 | switch (type_entry->id) { | 4509 | switch (type_entry->id) { |
| 4510 | case TypeTableEntryIdInvalid: | 4510 | case TypeTableEntryIdInvalid: |
| 4511 | case TypeTableEntryIdVar: | ||
| 4512 | case TypeTableEntryIdMetaType: | 4511 | case TypeTableEntryIdMetaType: |
| 4513 | case TypeTableEntryIdUnreachable: | 4512 | case TypeTableEntryIdUnreachable: |
| 4514 | case TypeTableEntryIdNumLitFloat: | 4513 | case TypeTableEntryIdNumLitFloat: |
| ... | @@ -4960,7 +4959,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c | ... | @@ -4960,7 +4959,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c |
| 4960 | case TypeTableEntryIdNamespace: | 4959 | case TypeTableEntryIdNamespace: |
| 4961 | case TypeTableEntryIdBlock: | 4960 | case TypeTableEntryIdBlock: |
| 4962 | case TypeTableEntryIdBoundFn: | 4961 | case TypeTableEntryIdBoundFn: |
| 4963 | case TypeTableEntryIdVar: | ||
| 4964 | case TypeTableEntryIdArgTuple: | 4962 | case TypeTableEntryIdArgTuple: |
| 4965 | case TypeTableEntryIdOpaque: | 4963 | case TypeTableEntryIdOpaque: |
| 4966 | case TypeTableEntryIdPromise: | 4964 | case TypeTableEntryIdPromise: |
| ... | @@ -5611,11 +5609,6 @@ static void define_builtin_types(CodeGen *g) { | ... | @@ -5611,11 +5609,6 @@ static void define_builtin_types(CodeGen *g) { |
| 5611 | entry->zero_bits = true; | 5609 | entry->zero_bits = true; |
| 5612 | g->builtin_types.entry_null = entry; | 5610 | g->builtin_types.entry_null = entry; |
| 5613 | } | 5611 | } |
| 5614 | { | ||
| 5615 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdVar); | ||
| 5616 | buf_init_from_str(&entry->name, "(var)"); | ||
| 5617 | g->builtin_types.entry_var = entry; | ||
| 5618 | } | ||
| 5619 | { | 5612 | { |
| 5620 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdArgTuple); | 5613 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdArgTuple); |
| 5621 | buf_init_from_str(&entry->name, "(args)"); | 5614 | buf_init_from_str(&entry->name, "(args)"); |
| ... | @@ -6444,7 +6437,6 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry | ... | @@ -6444,7 +6437,6 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry |
| 6444 | 6437 | ||
| 6445 | switch (type_entry->id) { | 6438 | switch (type_entry->id) { |
| 6446 | case TypeTableEntryIdInvalid: | 6439 | case TypeTableEntryIdInvalid: |
| 6447 | case TypeTableEntryIdVar: | ||
| 6448 | case TypeTableEntryIdMetaType: | 6440 | case TypeTableEntryIdMetaType: |
| 6449 | case TypeTableEntryIdNumLitFloat: | 6441 | case TypeTableEntryIdNumLitFloat: |
| 6450 | case TypeTableEntryIdNumLitInt: | 6442 | case TypeTableEntryIdNumLitInt: |
| ... | @@ -6639,7 +6631,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf | ... | @@ -6639,7 +6631,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf |
| 6639 | case TypeTableEntryIdNumLitInt: | 6631 | case TypeTableEntryIdNumLitInt: |
| 6640 | case TypeTableEntryIdUndefLit: | 6632 | case TypeTableEntryIdUndefLit: |
| 6641 | case TypeTableEntryIdNullLit: | 6633 | case TypeTableEntryIdNullLit: |
| 6642 | case TypeTableEntryIdVar: | ||
| 6643 | case TypeTableEntryIdArgTuple: | 6634 | case TypeTableEntryIdArgTuple: |
| 6644 | case TypeTableEntryIdPromise: | 6635 | case TypeTableEntryIdPromise: |
| 6645 | zig_unreachable(); | 6636 | zig_unreachable(); |
| ... | @@ -6781,7 +6772,6 @@ static void gen_h_file(CodeGen *g) { | ... | @@ -6781,7 +6772,6 @@ static void gen_h_file(CodeGen *g) { |
| 6781 | TypeTableEntry *type_entry = gen_h->types_to_declare.at(type_i); | 6772 | TypeTableEntry *type_entry = gen_h->types_to_declare.at(type_i); |
| 6782 | switch (type_entry->id) { | 6773 | switch (type_entry->id) { |
| 6783 | case TypeTableEntryIdInvalid: | 6774 | case TypeTableEntryIdInvalid: |
| 6784 | case TypeTableEntryIdVar: | ||
| 6785 | case TypeTableEntryIdMetaType: | 6775 | case TypeTableEntryIdMetaType: |
| 6786 | case TypeTableEntryIdVoid: | 6776 | case TypeTableEntryIdVoid: |
| 6787 | case TypeTableEntryIdBool: | 6777 | case TypeTableEntryIdBool: |
src/ir.cpp+50-72| ... | @@ -2147,7 +2147,7 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s | ... | @@ -2147,7 +2147,7 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s |
| 2147 | size_t param_count = source_node->data.fn_proto.params.length; | 2147 | size_t param_count = source_node->data.fn_proto.params.length; |
| 2148 | if (is_var_args) param_count -= 1; | 2148 | if (is_var_args) param_count -= 1; |
| 2149 | for (size_t i = 0; i < param_count; i += 1) { | 2149 | for (size_t i = 0; i < param_count; i += 1) { |
| 2150 | ir_ref_instruction(param_types[i], irb->current_basic_block); | 2150 | if (param_types[i] != nullptr) ir_ref_instruction(param_types[i], irb->current_basic_block); |
| 2151 | } | 2151 | } |
| 2152 | if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block); | 2152 | if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block); |
| 2153 | ir_ref_instruction(return_type, irb->current_basic_block); | 2153 | ir_ref_instruction(return_type, irb->current_basic_block); |
| ... | @@ -3305,12 +3305,6 @@ static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -3305,12 +3305,6 @@ static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode |
| 3305 | return ir_build_const_null(irb, scope, node); | 3305 | return ir_build_const_null(irb, scope, node); |
| 3306 | } | 3306 | } |
| 3307 | 3307 | ||
| 3308 | static IrInstruction *ir_gen_var_literal(IrBuilder *irb, Scope *scope, AstNode *node) { | ||
| 3309 | assert(node->type == NodeTypeVarLiteral); | ||
| 3310 | |||
| 3311 | return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_var); | ||
| 3312 | } | ||
| 3313 | |||
| 3314 | static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { | 3308 | static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { |
| 3315 | assert(node->type == NodeTypeSymbol); | 3309 | assert(node->type == NodeTypeSymbol); |
| 3316 | 3310 | ||
| ... | @@ -5916,11 +5910,15 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -5916,11 +5910,15 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5916 | is_var_args = true; | 5910 | is_var_args = true; |
| 5917 | break; | 5911 | break; |
| 5918 | } | 5912 | } |
| 5919 | AstNode *type_node = param_node->data.param_decl.type; | 5913 | if (param_node->data.param_decl.var_token == nullptr) { |
| 5920 | IrInstruction *type_value = ir_gen_node(irb, type_node, parent_scope); | 5914 | AstNode *type_node = param_node->data.param_decl.type; |
| 5921 | if (type_value == irb->codegen->invalid_instruction) | 5915 | IrInstruction *type_value = ir_gen_node(irb, type_node, parent_scope); |
| 5922 | return irb->codegen->invalid_instruction; | 5916 | if (type_value == irb->codegen->invalid_instruction) |
| 5923 | param_types[i] = type_value; | 5917 | return irb->codegen->invalid_instruction; |
| 5918 | param_types[i] = type_value; | ||
| 5919 | } else { | ||
| 5920 | param_types[i] = nullptr; | ||
| 5921 | } | ||
| 5924 | } | 5922 | } |
| 5925 | 5923 | ||
| 5926 | IrInstruction *align_value = nullptr; | 5924 | IrInstruction *align_value = nullptr; |
| ... | @@ -5931,12 +5929,16 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -5931,12 +5929,16 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5931 | } | 5929 | } |
| 5932 | 5930 | ||
| 5933 | IrInstruction *return_type; | 5931 | IrInstruction *return_type; |
| 5934 | if (node->data.fn_proto.return_type == nullptr) { | 5932 | if (node->data.fn_proto.return_var_token == nullptr) { |
| 5935 | return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void); | 5933 | if (node->data.fn_proto.return_type == nullptr) { |
| 5934 | return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void); | ||
| 5935 | } else { | ||
| 5936 | return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope); | ||
| 5937 | if (return_type == irb->codegen->invalid_instruction) | ||
| 5938 | return irb->codegen->invalid_instruction; | ||
| 5939 | } | ||
| 5936 | } else { | 5940 | } else { |
| 5937 | return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope); | 5941 | return_type = nullptr; |
| 5938 | if (return_type == irb->codegen->invalid_instruction) | ||
| 5939 | return irb->codegen->invalid_instruction; | ||
| 5940 | } | 5942 | } |
| 5941 | 5943 | ||
| 5942 | return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, return_type, is_var_args); | 5944 | return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, return_type, is_var_args); |
| ... | @@ -6189,8 +6191,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop | ... | @@ -6189,8 +6191,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 6189 | return ir_lval_wrap(irb, scope, ir_gen_asm_expr(irb, scope, node), lval); | 6191 | return ir_lval_wrap(irb, scope, ir_gen_asm_expr(irb, scope, node), lval); |
| 6190 | case NodeTypeNullLiteral: | 6192 | case NodeTypeNullLiteral: |
| 6191 | return ir_lval_wrap(irb, scope, ir_gen_null_literal(irb, scope, node), lval); | 6193 | return ir_lval_wrap(irb, scope, ir_gen_null_literal(irb, scope, node), lval); |
| 6192 | case NodeTypeVarLiteral: | ||
| 6193 | return ir_lval_wrap(irb, scope, ir_gen_var_literal(irb, scope, node), lval); | ||
| 6194 | case NodeTypeIfErrorExpr: | 6194 | case NodeTypeIfErrorExpr: |
| 6195 | return ir_lval_wrap(irb, scope, ir_gen_if_err_expr(irb, scope, node), lval); | 6195 | return ir_lval_wrap(irb, scope, ir_gen_if_err_expr(irb, scope, node), lval); |
| 6196 | case NodeTypeTestExpr: | 6196 | case NodeTypeTestExpr: |
| ... | @@ -7515,11 +7515,6 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, | ... | @@ -7515,11 +7515,6 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 7515 | return ImplicitCastMatchResultReportedError; | 7515 | return ImplicitCastMatchResultReportedError; |
| 7516 | } | 7516 | } |
| 7517 | 7517 | ||
| 7518 | // implicit conversion from anything to var | ||
| 7519 | if (expected_type->id == TypeTableEntryIdVar) { | ||
| 7520 | return ImplicitCastMatchResultYes; | ||
| 7521 | } | ||
| 7522 | |||
| 7523 | // implicit conversion from non maybe type to maybe type | 7518 | // implicit conversion from non maybe type to maybe type |
| 7524 | if (expected_type->id == TypeTableEntryIdMaybe && | 7519 | if (expected_type->id == TypeTableEntryIdMaybe && |
| 7525 | ir_types_match_with_implicit_cast(ira, expected_type->data.maybe.child_type, actual_type, value)) | 7520 | ir_types_match_with_implicit_cast(ira, expected_type->data.maybe.child_type, actual_type, value)) |
| ... | @@ -9341,9 +9336,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -9341,9 +9336,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 9341 | return ira->codegen->invalid_instruction; | 9336 | return ira->codegen->invalid_instruction; |
| 9342 | } | 9337 | } |
| 9343 | 9338 | ||
| 9344 | if (wanted_type->id == TypeTableEntryIdVar) | ||
| 9345 | return value; | ||
| 9346 | |||
| 9347 | // explicit match or non-const to const | 9339 | // explicit match or non-const to const |
| 9348 | if (types_match_const_cast_only(ira, wanted_type, actual_type, source_node).id == ConstCastResultIdOk) { | 9340 | if (types_match_const_cast_only(ira, wanted_type, actual_type, source_node).id == ConstCastResultIdOk) { |
| 9349 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false); | 9341 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false); |
| ... | @@ -10311,9 +10303,6 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -10311,9 +10303,6 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 10311 | ir_add_error_node(ira, source_node, | 10303 | ir_add_error_node(ira, source_node, |
| 10312 | buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name))); | 10304 | buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name))); |
| 10313 | return ira->codegen->builtin_types.entry_invalid; | 10305 | return ira->codegen->builtin_types.entry_invalid; |
| 10314 | |||
| 10315 | case TypeTableEntryIdVar: | ||
| 10316 | zig_unreachable(); | ||
| 10317 | } | 10306 | } |
| 10318 | 10307 | ||
| 10319 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type); | 10308 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type); |
| ... | @@ -11106,7 +11095,6 @@ static VarClassRequired get_var_class_required(TypeTableEntry *type_entry) { | ... | @@ -11106,7 +11095,6 @@ static VarClassRequired get_var_class_required(TypeTableEntry *type_entry) { |
| 11106 | case TypeTableEntryIdInvalid: | 11095 | case TypeTableEntryIdInvalid: |
| 11107 | zig_unreachable(); | 11096 | zig_unreachable(); |
| 11108 | case TypeTableEntryIdUnreachable: | 11097 | case TypeTableEntryIdUnreachable: |
| 11109 | case TypeTableEntryIdVar: | ||
| 11110 | return VarClassRequiredIllegal; | 11098 | return VarClassRequiredIllegal; |
| 11111 | case TypeTableEntryIdBool: | 11099 | case TypeTableEntryIdBool: |
| 11112 | case TypeTableEntryIdInt: | 11100 | case TypeTableEntryIdInt: |
| ... | @@ -11279,7 +11267,6 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi | ... | @@ -11279,7 +11267,6 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi |
| 11279 | 11267 | ||
| 11280 | switch (target->value.type->id) { | 11268 | switch (target->value.type->id) { |
| 11281 | case TypeTableEntryIdInvalid: | 11269 | case TypeTableEntryIdInvalid: |
| 11282 | case TypeTableEntryIdVar: | ||
| 11283 | case TypeTableEntryIdUnreachable: | 11270 | case TypeTableEntryIdUnreachable: |
| 11284 | zig_unreachable(); | 11271 | zig_unreachable(); |
| 11285 | case TypeTableEntryIdFn: { | 11272 | case TypeTableEntryIdFn: { |
| ... | @@ -11332,7 +11319,6 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi | ... | @@ -11332,7 +11319,6 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi |
| 11332 | TypeTableEntry *type_value = target->value.data.x_type; | 11319 | TypeTableEntry *type_value = target->value.data.x_type; |
| 11333 | switch (type_value->id) { | 11320 | switch (type_value->id) { |
| 11334 | case TypeTableEntryIdInvalid: | 11321 | case TypeTableEntryIdInvalid: |
| 11335 | case TypeTableEntryIdVar: | ||
| 11336 | zig_unreachable(); | 11322 | zig_unreachable(); |
| 11337 | case TypeTableEntryIdStruct: | 11323 | case TypeTableEntryIdStruct: |
| 11338 | if (is_slice(type_value)) { | 11324 | if (is_slice(type_value)) { |
| ... | @@ -11543,14 +11529,20 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node | ... | @@ -11543,14 +11529,20 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 11543 | { | 11529 | { |
| 11544 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i); | 11530 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i); |
| 11545 | assert(param_decl_node->type == NodeTypeParamDecl); | 11531 | assert(param_decl_node->type == NodeTypeParamDecl); |
| 11546 | AstNode *param_type_node = param_decl_node->data.param_decl.type; | ||
| 11547 | TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node); | ||
| 11548 | if (type_is_invalid(param_type)) | ||
| 11549 | return false; | ||
| 11550 | 11532 | ||
| 11551 | IrInstruction *casted_arg = ir_implicit_cast(ira, arg, param_type); | 11533 | IrInstruction *casted_arg; |
| 11552 | if (type_is_invalid(casted_arg->value.type)) | 11534 | if (param_decl_node->data.param_decl.var_token == nullptr) { |
| 11553 | return false; | 11535 | AstNode *param_type_node = param_decl_node->data.param_decl.type; |
| 11536 | TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node); | ||
| 11537 | if (type_is_invalid(param_type)) | ||
| 11538 | return false; | ||
| 11539 | |||
| 11540 | casted_arg = ir_implicit_cast(ira, arg, param_type); | ||
| 11541 | if (type_is_invalid(casted_arg->value.type)) | ||
| 11542 | return false; | ||
| 11543 | } else { | ||
| 11544 | casted_arg = arg; | ||
| 11545 | } | ||
| 11554 | 11546 | ||
| 11555 | ConstExprValue *arg_val = ir_resolve_const(ira, casted_arg, UndefBad); | 11547 | ConstExprValue *arg_val = ir_resolve_const(ira, casted_arg, UndefBad); |
| 11556 | if (!arg_val) | 11548 | if (!arg_val) |
| ... | @@ -11579,19 +11571,18 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod | ... | @@ -11579,19 +11571,18 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 11579 | arg_part_of_generic_id = true; | 11571 | arg_part_of_generic_id = true; |
| 11580 | casted_arg = ir_implicit_byval_const_ref_cast(ira, arg); | 11572 | casted_arg = ir_implicit_byval_const_ref_cast(ira, arg); |
| 11581 | } else { | 11573 | } else { |
| 11582 | AstNode *param_type_node = param_decl_node->data.param_decl.type; | 11574 | if (param_decl_node->data.param_decl.var_token == nullptr) { |
| 11583 | TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node); | 11575 | AstNode *param_type_node = param_decl_node->data.param_decl.type; |
| 11584 | if (type_is_invalid(param_type)) | 11576 | TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node); |
| 11585 | return false; | 11577 | if (type_is_invalid(param_type)) |
| 11578 | return false; | ||
| 11586 | 11579 | ||
| 11587 | bool is_var_type = (param_type->id == TypeTableEntryIdVar); | ||
| 11588 | if (is_var_type) { | ||
| 11589 | arg_part_of_generic_id = true; | ||
| 11590 | casted_arg = ir_implicit_byval_const_ref_cast(ira, arg); | ||
| 11591 | } else { | ||
| 11592 | casted_arg = ir_implicit_cast(ira, arg, param_type); | 11580 | casted_arg = ir_implicit_cast(ira, arg, param_type); |
| 11593 | if (type_is_invalid(casted_arg->value.type)) | 11581 | if (type_is_invalid(casted_arg->value.type)) |
| 11594 | return false; | 11582 | return false; |
| 11583 | } else { | ||
| 11584 | arg_part_of_generic_id = true; | ||
| 11585 | casted_arg = ir_implicit_byval_const_ref_cast(ira, arg); | ||
| 11595 | } | 11586 | } |
| 11596 | } | 11587 | } |
| 11597 | 11588 | ||
| ... | @@ -12304,7 +12295,6 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op | ... | @@ -12304,7 +12295,6 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op |
| 12304 | return ira->codegen->builtin_types.entry_invalid; | 12295 | return ira->codegen->builtin_types.entry_invalid; |
| 12305 | switch (type_entry->id) { | 12296 | switch (type_entry->id) { |
| 12306 | case TypeTableEntryIdInvalid: | 12297 | case TypeTableEntryIdInvalid: |
| 12307 | case TypeTableEntryIdVar: | ||
| 12308 | zig_unreachable(); | 12298 | zig_unreachable(); |
| 12309 | case TypeTableEntryIdMetaType: | 12299 | case TypeTableEntryIdMetaType: |
| 12310 | case TypeTableEntryIdVoid: | 12300 | case TypeTableEntryIdVoid: |
| ... | @@ -13539,10 +13529,6 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi | ... | @@ -13539,10 +13529,6 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi |
| 13539 | switch (type_entry->id) { | 13529 | switch (type_entry->id) { |
| 13540 | case TypeTableEntryIdInvalid: | 13530 | case TypeTableEntryIdInvalid: |
| 13541 | zig_unreachable(); // handled above | 13531 | zig_unreachable(); // handled above |
| 13542 | case TypeTableEntryIdVar: | ||
| 13543 | ir_add_error_node(ira, expr_value->source_node, | ||
| 13544 | buf_sprintf("type '%s' not eligible for @typeOf", buf_ptr(&type_entry->name))); | ||
| 13545 | return ira->codegen->builtin_types.entry_invalid; | ||
| 13546 | case TypeTableEntryIdNumLitFloat: | 13532 | case TypeTableEntryIdNumLitFloat: |
| 13547 | case TypeTableEntryIdNumLitInt: | 13533 | case TypeTableEntryIdNumLitInt: |
| 13548 | case TypeTableEntryIdUndefLit: | 13534 | case TypeTableEntryIdUndefLit: |
| ... | @@ -13807,7 +13793,6 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, | ... | @@ -13807,7 +13793,6 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 13807 | switch (child_type->id) { | 13793 | switch (child_type->id) { |
| 13808 | case TypeTableEntryIdInvalid: // handled above | 13794 | case TypeTableEntryIdInvalid: // handled above |
| 13809 | zig_unreachable(); | 13795 | zig_unreachable(); |
| 13810 | case TypeTableEntryIdVar: | ||
| 13811 | case TypeTableEntryIdUnreachable: | 13796 | case TypeTableEntryIdUnreachable: |
| 13812 | case TypeTableEntryIdUndefLit: | 13797 | case TypeTableEntryIdUndefLit: |
| 13813 | case TypeTableEntryIdNullLit: | 13798 | case TypeTableEntryIdNullLit: |
| ... | @@ -13916,7 +13901,6 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, | ... | @@ -13916,7 +13901,6 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 13916 | switch (child_type->id) { | 13901 | switch (child_type->id) { |
| 13917 | case TypeTableEntryIdInvalid: // handled above | 13902 | case TypeTableEntryIdInvalid: // handled above |
| 13918 | zig_unreachable(); | 13903 | zig_unreachable(); |
| 13919 | case TypeTableEntryIdVar: | ||
| 13920 | case TypeTableEntryIdUnreachable: | 13904 | case TypeTableEntryIdUnreachable: |
| 13921 | case TypeTableEntryIdUndefLit: | 13905 | case TypeTableEntryIdUndefLit: |
| 13922 | case TypeTableEntryIdNullLit: | 13906 | case TypeTableEntryIdNullLit: |
| ... | @@ -13968,7 +13952,6 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira, | ... | @@ -13968,7 +13952,6 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira, |
| 13968 | switch (type_entry->id) { | 13952 | switch (type_entry->id) { |
| 13969 | case TypeTableEntryIdInvalid: // handled above | 13953 | case TypeTableEntryIdInvalid: // handled above |
| 13970 | zig_unreachable(); | 13954 | zig_unreachable(); |
| 13971 | case TypeTableEntryIdVar: | ||
| 13972 | case TypeTableEntryIdUnreachable: | 13955 | case TypeTableEntryIdUnreachable: |
| 13973 | case TypeTableEntryIdUndefLit: | 13956 | case TypeTableEntryIdUndefLit: |
| 13974 | case TypeTableEntryIdNullLit: | 13957 | case TypeTableEntryIdNullLit: |
| ... | @@ -14316,7 +14299,6 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -14316,7 +14299,6 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 14316 | 14299 | ||
| 14317 | switch (target_type->id) { | 14300 | switch (target_type->id) { |
| 14318 | case TypeTableEntryIdInvalid: | 14301 | case TypeTableEntryIdInvalid: |
| 14319 | case TypeTableEntryIdVar: | ||
| 14320 | zig_unreachable(); | 14302 | zig_unreachable(); |
| 14321 | case TypeTableEntryIdMetaType: | 14303 | case TypeTableEntryIdMetaType: |
| 14322 | case TypeTableEntryIdVoid: | 14304 | case TypeTableEntryIdVoid: |
| ... | @@ -14911,7 +14893,6 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -14911,7 +14893,6 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_ |
| 14911 | } | 14893 | } |
| 14912 | case TypeTableEntryIdEnum: | 14894 | case TypeTableEntryIdEnum: |
| 14913 | zig_panic("TODO min/max value for enum type"); | 14895 | zig_panic("TODO min/max value for enum type"); |
| 14914 | case TypeTableEntryIdVar: | ||
| 14915 | case TypeTableEntryIdMetaType: | 14896 | case TypeTableEntryIdMetaType: |
| 14916 | case TypeTableEntryIdUnreachable: | 14897 | case TypeTableEntryIdUnreachable: |
| 14917 | case TypeTableEntryIdPointer: | 14898 | case TypeTableEntryIdPointer: |
| ... | @@ -16159,7 +16140,6 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc | ... | @@ -16159,7 +16140,6 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc |
| 16159 | 16140 | ||
| 16160 | switch (type_entry->id) { | 16141 | switch (type_entry->id) { |
| 16161 | case TypeTableEntryIdInvalid: | 16142 | case TypeTableEntryIdInvalid: |
| 16162 | case TypeTableEntryIdVar: | ||
| 16163 | zig_unreachable(); | 16143 | zig_unreachable(); |
| 16164 | case TypeTableEntryIdMetaType: | 16144 | case TypeTableEntryIdMetaType: |
| 16165 | case TypeTableEntryIdUnreachable: | 16145 | case TypeTableEntryIdUnreachable: |
| ... | @@ -16461,21 +16441,23 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc | ... | @@ -16461,21 +16441,23 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc |
| 16461 | zig_unreachable(); | 16441 | zig_unreachable(); |
| 16462 | } | 16442 | } |
| 16463 | } | 16443 | } |
| 16464 | IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->other; | ||
| 16465 | if (type_is_invalid(param_type_value->value.type)) | ||
| 16466 | return ira->codegen->builtin_types.entry_invalid; | ||
| 16467 | |||
| 16468 | FnTypeParamInfo *param_info = &fn_type_id.param_info[fn_type_id.next_param_index]; | 16444 | FnTypeParamInfo *param_info = &fn_type_id.param_info[fn_type_id.next_param_index]; |
| 16469 | param_info->is_noalias = param_node->data.param_decl.is_noalias; | 16445 | param_info->is_noalias = param_node->data.param_decl.is_noalias; |
| 16470 | param_info->type = ir_resolve_type(ira, param_type_value); | ||
| 16471 | if (type_is_invalid(param_info->type)) | ||
| 16472 | return ira->codegen->builtin_types.entry_invalid; | ||
| 16473 | 16446 | ||
| 16474 | if (param_info->type->id == TypeTableEntryIdVar) { | 16447 | if (instruction->param_types[fn_type_id.next_param_index] == nullptr) { |
| 16448 | param_info->type = nullptr; | ||
| 16475 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 16449 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 16476 | out_val->data.x_type = get_generic_fn_type(ira->codegen, &fn_type_id); | 16450 | out_val->data.x_type = get_generic_fn_type(ira->codegen, &fn_type_id); |
| 16477 | return ira->codegen->builtin_types.entry_type; | 16451 | return ira->codegen->builtin_types.entry_type; |
| 16452 | } else { | ||
| 16453 | IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->other; | ||
| 16454 | if (type_is_invalid(param_type_value->value.type)) | ||
| 16455 | return ira->codegen->builtin_types.entry_invalid; | ||
| 16456 | param_info->type = ir_resolve_type(ira, param_type_value); | ||
| 16457 | if (type_is_invalid(param_info->type)) | ||
| 16458 | return ira->codegen->builtin_types.entry_invalid; | ||
| 16478 | } | 16459 | } |
| 16460 | |||
| 16479 | } | 16461 | } |
| 16480 | 16462 | ||
| 16481 | if (instruction->align_value != nullptr) { | 16463 | if (instruction->align_value != nullptr) { |
| ... | @@ -16869,7 +16851,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue | ... | @@ -16869,7 +16851,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 16869 | assert(val->special == ConstValSpecialStatic); | 16851 | assert(val->special == ConstValSpecialStatic); |
| 16870 | switch (val->type->id) { | 16852 | switch (val->type->id) { |
| 16871 | case TypeTableEntryIdInvalid: | 16853 | case TypeTableEntryIdInvalid: |
| 16872 | case TypeTableEntryIdVar: | ||
| 16873 | case TypeTableEntryIdMetaType: | 16854 | case TypeTableEntryIdMetaType: |
| 16874 | case TypeTableEntryIdOpaque: | 16855 | case TypeTableEntryIdOpaque: |
| 16875 | case TypeTableEntryIdBoundFn: | 16856 | case TypeTableEntryIdBoundFn: |
| ... | @@ -16937,7 +16918,6 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue | ... | @@ -16937,7 +16918,6 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 16937 | assert(val->special == ConstValSpecialStatic); | 16918 | assert(val->special == ConstValSpecialStatic); |
| 16938 | switch (val->type->id) { | 16919 | switch (val->type->id) { |
| 16939 | case TypeTableEntryIdInvalid: | 16920 | case TypeTableEntryIdInvalid: |
| 16940 | case TypeTableEntryIdVar: | ||
| 16941 | case TypeTableEntryIdMetaType: | 16921 | case TypeTableEntryIdMetaType: |
| 16942 | case TypeTableEntryIdOpaque: | 16922 | case TypeTableEntryIdOpaque: |
| 16943 | case TypeTableEntryIdBoundFn: | 16923 | case TypeTableEntryIdBoundFn: |
| ... | @@ -17014,7 +16994,6 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc | ... | @@ -17014,7 +16994,6 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc |
| 17014 | 16994 | ||
| 17015 | switch (src_type->id) { | 16995 | switch (src_type->id) { |
| 17016 | case TypeTableEntryIdInvalid: | 16996 | case TypeTableEntryIdInvalid: |
| 17017 | case TypeTableEntryIdVar: | ||
| 17018 | case TypeTableEntryIdMetaType: | 16997 | case TypeTableEntryIdMetaType: |
| 17019 | case TypeTableEntryIdOpaque: | 16998 | case TypeTableEntryIdOpaque: |
| 17020 | case TypeTableEntryIdBoundFn: | 16999 | case TypeTableEntryIdBoundFn: |
| ... | @@ -17041,7 +17020,6 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc | ... | @@ -17041,7 +17020,6 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc |
| 17041 | 17020 | ||
| 17042 | switch (dest_type->id) { | 17021 | switch (dest_type->id) { |
| 17043 | case TypeTableEntryIdInvalid: | 17022 | case TypeTableEntryIdInvalid: |
| 17044 | case TypeTableEntryIdVar: | ||
| 17045 | case TypeTableEntryIdMetaType: | 17023 | case TypeTableEntryIdMetaType: |
| 17046 | case TypeTableEntryIdOpaque: | 17024 | case TypeTableEntryIdOpaque: |
| 17047 | case TypeTableEntryIdBoundFn: | 17025 | case TypeTableEntryIdBoundFn: |
src/parser.cpp+23-24| ... | @@ -263,21 +263,14 @@ static AstNode *ast_parse_error_set_expr(ParseContext *pc, size_t *token_index, | ... | @@ -263,21 +263,14 @@ static AstNode *ast_parse_error_set_expr(ParseContext *pc, size_t *token_index, |
| 263 | } | 263 | } |
| 264 | 264 | ||
| 265 | /* | 265 | /* |
| 266 | TypeExpr = ErrorSetExpr | "var" | 266 | TypeExpr = ErrorSetExpr |
| 267 | */ | 267 | */ |
| 268 | static AstNode *ast_parse_type_expr(ParseContext *pc, size_t *token_index, bool mandatory) { | 268 | static AstNode *ast_parse_type_expr(ParseContext *pc, size_t *token_index, bool mandatory) { |
| 269 | Token *token = &pc->tokens->at(*token_index); | 269 | return ast_parse_error_set_expr(pc, token_index, mandatory); |
| 270 | if (token->id == TokenIdKeywordVar) { | ||
| 271 | AstNode *node = ast_create_node(pc, NodeTypeVarLiteral, token); | ||
| 272 | *token_index += 1; | ||
| 273 | return node; | ||
| 274 | } else { | ||
| 275 | return ast_parse_error_set_expr(pc, token_index, mandatory); | ||
| 276 | } | ||
| 277 | } | 270 | } |
| 278 | 271 | ||
| 279 | /* | 272 | /* |
| 280 | ParamDecl = option("noalias" | "comptime") option(Symbol ":") (TypeExpr | "...") | 273 | ParamDecl = option("noalias" | "comptime") option(Symbol ":") (TypeExpr | "var" | "...") |
| 281 | */ | 274 | */ |
| 282 | static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) { | 275 | static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) { |
| 283 | Token *token = &pc->tokens->at(*token_index); | 276 | Token *token = &pc->tokens->at(*token_index); |
| ... | @@ -308,6 +301,9 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) { | ... | @@ -308,6 +301,9 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) { |
| 308 | if (ellipsis_tok->id == TokenIdEllipsis3) { | 301 | if (ellipsis_tok->id == TokenIdEllipsis3) { |
| 309 | *token_index += 1; | 302 | *token_index += 1; |
| 310 | node->data.param_decl.is_var_args = true; | 303 | node->data.param_decl.is_var_args = true; |
| 304 | } else if (ellipsis_tok->id == TokenIdKeywordVar) { | ||
| 305 | *token_index += 1; | ||
| 306 | node->data.param_decl.var_token = ellipsis_tok; | ||
| 311 | } else { | 307 | } else { |
| 312 | node->data.param_decl.type = ast_parse_type_expr(pc, token_index, true); | 308 | node->data.param_decl.type = ast_parse_type_expr(pc, token_index, true); |
| 313 | } | 309 | } |
| ... | @@ -2421,7 +2417,7 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand | ... | @@ -2421,7 +2417,7 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand |
| 2421 | } | 2417 | } |
| 2422 | 2418 | ||
| 2423 | /* | 2419 | /* |
| 2424 | FnProto = option("nakedcc" | "stdcallcc" | "extern" | ("async" option("(" Expression ")"))) "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("!") TypeExpr | 2420 | FnProto = option("nakedcc" | "stdcallcc" | "extern" | ("async" option("(" Expression ")"))) "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("!") (TypeExpr | "var") |
| 2425 | */ | 2421 | */ |
| 2426 | static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool mandatory, VisibMod visib_mod) { | 2422 | static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool mandatory, VisibMod visib_mod) { |
| 2427 | Token *first_token = &pc->tokens->at(*token_index); | 2423 | Token *first_token = &pc->tokens->at(*token_index); |
| ... | @@ -2507,19 +2503,25 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m | ... | @@ -2507,19 +2503,25 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m |
| 2507 | ast_eat_token(pc, token_index, TokenIdRParen); | 2503 | ast_eat_token(pc, token_index, TokenIdRParen); |
| 2508 | next_token = &pc->tokens->at(*token_index); | 2504 | next_token = &pc->tokens->at(*token_index); |
| 2509 | } | 2505 | } |
| 2510 | if (next_token->id == TokenIdKeywordError) { | 2506 | if (next_token->id == TokenIdKeywordVar) { |
| 2511 | Token *maybe_lbrace_tok = &pc->tokens->at(*token_index + 1); | 2507 | node->data.fn_proto.return_var_token = next_token; |
| 2512 | if (maybe_lbrace_tok->id == TokenIdLBrace) { | ||
| 2513 | *token_index += 1; | ||
| 2514 | node->data.fn_proto.return_type = ast_create_node(pc, NodeTypeErrorType, next_token); | ||
| 2515 | return node; | ||
| 2516 | } | ||
| 2517 | } else if (next_token->id == TokenIdBang) { | ||
| 2518 | *token_index += 1; | 2508 | *token_index += 1; |
| 2519 | node->data.fn_proto.auto_err_set = true; | ||
| 2520 | next_token = &pc->tokens->at(*token_index); | 2509 | next_token = &pc->tokens->at(*token_index); |
| 2510 | } else { | ||
| 2511 | if (next_token->id == TokenIdKeywordError) { | ||
| 2512 | Token *maybe_lbrace_tok = &pc->tokens->at(*token_index + 1); | ||
| 2513 | if (maybe_lbrace_tok->id == TokenIdLBrace) { | ||
| 2514 | *token_index += 1; | ||
| 2515 | node->data.fn_proto.return_type = ast_create_node(pc, NodeTypeErrorType, next_token); | ||
| 2516 | return node; | ||
| 2517 | } | ||
| 2518 | } else if (next_token->id == TokenIdBang) { | ||
| 2519 | *token_index += 1; | ||
| 2520 | node->data.fn_proto.auto_err_set = true; | ||
| 2521 | next_token = &pc->tokens->at(*token_index); | ||
| 2522 | } | ||
| 2523 | node->data.fn_proto.return_type = ast_parse_type_expr(pc, token_index, true); | ||
| 2521 | } | 2524 | } |
| 2522 | node->data.fn_proto.return_type = ast_parse_type_expr(pc, token_index, true); | ||
| 2523 | 2525 | ||
| 2524 | return node; | 2526 | return node; |
| 2525 | } | 2527 | } |
| ... | @@ -3069,9 +3071,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont | ... | @@ -3069,9 +3071,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont |
| 3069 | case NodeTypeErrorType: | 3071 | case NodeTypeErrorType: |
| 3070 | // none | 3072 | // none |
| 3071 | break; | 3073 | break; |
| 3072 | case NodeTypeVarLiteral: | ||
| 3073 | // none | ||
| 3074 | break; | ||
| 3075 | case NodeTypeAddrOfExpr: | 3074 | case NodeTypeAddrOfExpr: |
| 3076 | visit_field(&node->data.addr_of_expr.align_expr, visit, context); | 3075 | visit_field(&node->data.addr_of_expr.align_expr, visit, context); |
| 3077 | visit_field(&node->data.addr_of_expr.op_expr, visit, context); | 3076 | visit_field(&node->data.addr_of_expr.op_expr, visit, context); |
test/compile_errors.zig+7| ... | @@ -1,6 +1,13 @@ | ... | @@ -1,6 +1,13 @@ |
| 1 | const tests = @import("tests.zig"); | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | ||
| 3 | pub fn addCases(cases: &tests.CompileErrorContext) void { | 3 | pub fn addCases(cases: &tests.CompileErrorContext) void { |
| 4 | cases.add("var not allowed in structs", | ||
| 5 | \\export fn entry() void { | ||
| 6 | \\ var s = (struct{v: var}){.v=i32(10)}; | ||
| 7 | \\} | ||
| 8 | , | ||
| 9 | ".tmp_source.zig:2:23: error: invalid token: 'var'"); | ||
| 10 | |||
| 4 | cases.add("@ptrCast discards const qualifier", | 11 | cases.add("@ptrCast discards const qualifier", |
| 5 | \\export fn entry() void { | 12 | \\export fn entry() void { |
| 6 | \\ const x: i32 = 1234; | 13 | \\ const x: i32 = 1234; |