From ee982ae162901078458003fad169ddb1cf4d1d06 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 8 Feb 2018 22:30:08 -0500 Subject: [PATCH] syntax: parse `?error!i32` as `?(error!i32)` --- TODO | 6 ------ doc/langref.html.in | 2 +- src/parser.cpp | 4 ++-- test/cases/error.zig | 6 ++++++ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index f67feb1630..5da999b457 100644 --- a/TODO +++ b/TODO @@ -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 - diff --git a/doc/langref.html.in b/doc/langref.html.in index 31a2f6a6c9..2b09ca81bd 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -5743,7 +5743,7 @@ CurlySuffixExpression = TypeExpr option(ContainerInitExpression) MultiplyOperator = "||" | "*" | "/" | "%" | "**" | "*%" -PrefixOpExpression = PrefixOp PrefixOpExpression | SuffixOpExpression +PrefixOpExpression = PrefixOp ErrorSetExpr | SuffixOpExpression SuffixOpExpression = PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression) diff --git a/src/parser.cpp b/src/parser.cpp index b72de374ba..6ce9e25221 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -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; diff --git a/test/cases/error.zig b/test/cases/error.zig index a8150620b2..61e0b375a2 100644 --- a/test/cases/error.zig +++ b/test/cases/error.zig @@ -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)); + } +}