diff --git a/liblangutil/Scanner.cpp b/liblangutil/Scanner.cpp index b6011342d..1a3903d5c 100644 --- a/liblangutil/Scanner.cpp +++ b/liblangutil/Scanner.cpp @@ -668,7 +668,7 @@ void Scanner::scanToken() tie(token, m, n) = scanIdentifierOrKeyword(); // Special case for hexadecimal literals - if (token == Token::Hex && m_kind != ScannerKind::Yul) + if (token == Token::Hex) { // reset m = 0; diff --git a/liblangutil/Token.h b/liblangutil/Token.h index ecebe0cf5..2bfc58e44 100644 --- a/liblangutil/Token.h +++ b/liblangutil/Token.h @@ -324,7 +324,7 @@ namespace TokenTraits { return tok == Token::Function || tok == Token::Let || tok == Token::If || tok == Token::Switch || tok == Token::Case || tok == Token::Default || tok == Token::For || tok == Token::Break || tok == Token::Continue || tok == Token::Leave || - tok == Token::TrueLiteral || tok == Token::FalseLiteral; + tok == Token::TrueLiteral || tok == Token::FalseLiteral || tok == Token::HexStringLiteral || tok == Token::Hex; } inline Token AssignmentToBinaryOp(Token op) diff --git a/libyul/AsmParser.cpp b/libyul/AsmParser.cpp index e85bafb67..2baefa16f 100644 --- a/libyul/AsmParser.cpp +++ b/libyul/AsmParser.cpp @@ -337,6 +337,9 @@ Parser::ElementaryOperation Parser::parseElementaryOperation() ret = std::move(literal); break; } + case Token::HexStringLiteral: + fatalParserError(3772_error, "Hex literals are not valid in this context."); + break; default: fatalParserError(1856_error, "Literal or identifier expected."); } diff --git a/test/liblangutil/Scanner.cpp b/test/liblangutil/Scanner.cpp index 2bb934fee..2110cb2b6 100644 --- a/test/liblangutil/Scanner.cpp +++ b/test/liblangutil/Scanner.cpp @@ -652,9 +652,8 @@ BOOST_AUTO_TEST_CASE(hex_prefix_only) BOOST_CHECK_EQUAL(scanner.currentError(), ScannerError::IllegalToken); scanner.reset(CharStream("{ hex", "")); scanner.setScannerMode(ScannerKind::Yul); - BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace); - BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); - BOOST_CHECK_EQUAL(scanner.currentLiteral(), "hex"); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); + BOOST_CHECK_EQUAL(scanner.currentError(), ScannerError::IllegalToken); } BOOST_AUTO_TEST_CASE(hex_invalid_space) @@ -674,10 +673,8 @@ BOOST_AUTO_TEST_CASE(hex_invalid_token) scanner.reset(CharStream("{ hex test", "")); scanner.setScannerMode(ScannerKind::Yul); BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace); - BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); - BOOST_CHECK_EQUAL(scanner.currentLiteral(), "hex"); - BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); - BOOST_CHECK_EQUAL(scanner.currentLiteral(), "test"); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); + BOOST_CHECK_EQUAL(scanner.currentError(), ScannerError::IllegalToken); } BOOST_AUTO_TEST_CASE(valid_hex_literal) diff --git a/test/libsolidity/syntaxTests/inlineAssembly/hex_assignment.sol b/test/libsolidity/syntaxTests/inlineAssembly/hex_assignment.sol index 3821a5073..b51dd8604 100644 --- a/test/libsolidity/syntaxTests/inlineAssembly/hex_assignment.sol +++ b/test/libsolidity/syntaxTests/inlineAssembly/hex_assignment.sol @@ -6,4 +6,4 @@ contract C { } } // ---- -// ParserError 6913: (86-87): Call or assignment expected. +// ParserError 3772: (72-81): Hex literals are not valid in this context. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/hex_expression.sol b/test/libsolidity/syntaxTests/inlineAssembly/hex_expression.sol index d4cbe810b..2f4f69174 100644 --- a/test/libsolidity/syntaxTests/inlineAssembly/hex_expression.sol +++ b/test/libsolidity/syntaxTests/inlineAssembly/hex_expression.sol @@ -6,4 +6,4 @@ contract C { } } // ---- -// ParserError 2314: (70-76): Expected ',' but got 'StringLiteral' +// ParserError 3772: (67-76): Hex literals are not valid in this context. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/hex_switch_case.sol b/test/libsolidity/syntaxTests/inlineAssembly/hex_switch_case.sol index 38f1f9637..de64567d7 100644 --- a/test/libsolidity/syntaxTests/inlineAssembly/hex_switch_case.sol +++ b/test/libsolidity/syntaxTests/inlineAssembly/hex_switch_case.sol @@ -8,4 +8,4 @@ contract C { } } // ---- -// ParserError 4805: (95-99): Literal expected. +// ParserError 3772: (92-99): Hex literals are not valid in this context. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/solidity_keywords.sol b/test/libsolidity/syntaxTests/inlineAssembly/solidity_keywords.sol index 9b5e570be..5467d045a 100644 --- a/test/libsolidity/syntaxTests/inlineAssembly/solidity_keywords.sol +++ b/test/libsolidity/syntaxTests/inlineAssembly/solidity_keywords.sol @@ -21,7 +21,7 @@ contract C { let fallback := 1 // for is a Yul keyword // function is a Yul keyword - let hex := 1 + // hex is a Yul keyword // if is a Yul keyword let indexed := 1 let interface := 1 @@ -110,4 +110,4 @@ contract C { } } // ---- -// Warning 5740: (944-2157): Unreachable code. +// Warning 5740: (955-2168): Unreachable code. diff --git a/test/libyul/yulSyntaxTests/hex_assignment.yul b/test/libyul/yulSyntaxTests/hex_assignment.yul index 9305cd3f2..213163916 100644 --- a/test/libyul/yulSyntaxTests/hex_assignment.yul +++ b/test/libyul/yulSyntaxTests/hex_assignment.yul @@ -2,4 +2,4 @@ let x := hex"0011" } // ---- -// ParserError 6913: (25-26): Call or assignment expected. +// ParserError 3772: (15-24): Hex literals are not valid in this context. diff --git a/test/libyul/yulSyntaxTests/hex_expression.yul b/test/libyul/yulSyntaxTests/hex_expression.yul index 02c8d78e6..191fdf085 100644 --- a/test/libyul/yulSyntaxTests/hex_expression.yul +++ b/test/libyul/yulSyntaxTests/hex_expression.yul @@ -2,4 +2,4 @@ pop(hex"2233") } // ---- -// ParserError 2314: (13-19): Expected ',' but got 'StringLiteral' +// ParserError 3772: (10-19): Hex literals are not valid in this context. diff --git a/test/libyul/yulSyntaxTests/hex_switch_case.yul b/test/libyul/yulSyntaxTests/hex_switch_case.yul index 4034b4797..87ba6a4a9 100644 --- a/test/libyul/yulSyntaxTests/hex_switch_case.yul +++ b/test/libyul/yulSyntaxTests/hex_switch_case.yul @@ -4,4 +4,4 @@ case hex"1122" {} } // ---- -// ParserError 4805: (36-40): Literal expected. +// ParserError 3772: (33-40): Hex literals are not valid in this context. diff --git a/test/libyul/yulSyntaxTests/solidity_keywords.yul b/test/libyul/yulSyntaxTests/solidity_keywords.yul index 4868fadad..1f1dafc53 100644 --- a/test/libyul/yulSyntaxTests/solidity_keywords.yul +++ b/test/libyul/yulSyntaxTests/solidity_keywords.yul @@ -19,7 +19,7 @@ let fallback := 1 // for is a Yul keyword // function is a Yul keyword - let hex := 1 + // hex is a Yul keyword // if is a Yul keyword let indexed := 1 let interface := 1