Skip to content

Commit

Permalink
Report an error for unbased unsized literal with question mark character
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed Oct 18, 2024
1 parent 2e6c82b commit 34148f2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 0 additions & 1 deletion source/parsing/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,6 @@ Token Lexer::lexApostrophe() {
return create(TokenKind::UnbasedUnsizedLiteral, logic_t::x);
case 'Z':
case 'z':
case '?':
advance();
return create(TokenKind::UnbasedUnsizedLiteral, logic_t::z);
case 's':
Expand Down
6 changes: 5 additions & 1 deletion source/parsing/Parser_expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ ExpressionSyntax& Parser::parseSubExpression(bitmask<ExpressionOptions> options,
if (isNewExpr(leftOperand))
return parseNewExpression(leftOperand->as<NameSyntax>(), options);

leftOperand = &parsePostfixExpression(*leftOperand, options);
// Don't try to parse postfix if we didn't find a valid primary to begin with.
if (leftOperand->kind != SyntaxKind::IdentifierName ||
!leftOperand->as<IdentifierNameSyntax>().identifier.isMissing()) {
leftOperand = &parsePostfixExpression(*leftOperand, options);
}
}

options &= ~ExpressionOptions::AllowSuperNewCall;
Expand Down
13 changes: 13 additions & 0 deletions tests/unittests/parsing/ExpressionParsingTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,3 +978,16 @@ endclass
REQUIRE(diagnostics.size() == 1);
CHECK(diagnostics[0].code == diag::WrongLanguageVersion);
}

TEST_CASE("Unbased unsized question mark parsing") {
auto& text = R"(
module bug(input logic [1:0] a, input logic s, output logic [1:0]y);
assign y = s? a: '?;
endmodule
)";

parseCompilationUnit(text);

REQUIRE(diagnostics.size() == 1);
CHECK(diagnostics[0].code == diag::ExpectedExpression);
}

0 comments on commit 34148f2

Please sign in to comment.