syntax: parse ?error!i32 as ?(error!i32)

This commit is contained in:
Andrew Kelley 2018-02-08 22:30:08 -05:00
parent 0efe441dfd
commit ee982ae162
4 changed files with 9 additions and 9 deletions

6
TODO
View File

@ -2,15 +2,9 @@ comptime calling fn with inferred error set should give empty error set but stil
comptime err to int of empty err set and of size 1 err set
comptime test for err
undefined in infer error
syntax - ?a!b should be ?(a!b) but it's (?a)!b
syntax - (error{}!void) as the return type
passing a fn()error{}!T to a fn()error!T should be a compile error, they're not compatible

View File

@ -5743,7 +5743,7 @@ CurlySuffixExpression = TypeExpr option(ContainerInitExpression)
MultiplyOperator = "||" | "*" | "/" | "%" | "**" | "*%"
PrefixOpExpression = PrefixOp PrefixOpExpression | SuffixOpExpression
PrefixOpExpression = PrefixOp ErrorSetExpr | SuffixOpExpression
SuffixOpExpression = PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression)

View File

@ -1041,7 +1041,7 @@ static AstNode *ast_parse_addr_of(ParseContext *pc, size_t *token_index) {
}
/*
PrefixOpExpression : PrefixOp PrefixOpExpression | SuffixOpExpression
PrefixOpExpression = PrefixOp ErrorSetExpr | SuffixOpExpression
PrefixOp = "!" | "-" | "~" | "*" | ("&" option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "??" | "-%" | "try"
*/
static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
@ -1072,7 +1072,7 @@ static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index,
node->column += 1;
}
AstNode *prefix_op_expr = ast_parse_prefix_op_expr(pc, token_index, true);
AstNode *prefix_op_expr = ast_parse_error_set_expr(pc, token_index, true);
node->data.prefix_op_expr.primary_expr = prefix_op_expr;
node->data.prefix_op_expr.prefix_op = prefix_op;

View File

@ -134,3 +134,9 @@ const EmptyErrorSet = error {};
fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) void {
if (x) |v| assert(v == 1234) else |err| @compileError("bad");
}
test "syntax: nullable operator in front of error union operator" {
comptime {
assert(?error!i32 == ?(error!i32));
}
}