Changed error message for for Unicode character in non-unicode string literal

Co-authored-by: Kamil Śliwak <cameel2@gmail.com>
This commit is contained in:
Samuel Osewa 2022-05-15 14:24:23 +01:00 committed by nishant-sachdeva
parent 9542e46ea4
commit c21265f9f8
6 changed files with 18 additions and 3 deletions

View File

@ -76,6 +76,7 @@ string to_string(ScannerError _errorCode)
case ScannerError::IllegalHexDigit: return "Hexadecimal digit missing or invalid.";
case ScannerError::IllegalCommentTerminator: return "Expected multi-line comment-terminator.";
case ScannerError::IllegalEscapeSequence: return "Invalid escape sequence.";
case ScannerError::UnicodeCharacterInNonUnicodeString: return "Invalid character in string. If you are trying to use Unicode characters, use a unicode\"...\" string literal.";
case ScannerError::IllegalCharacterInString: return "Invalid character in string.";
case ScannerError::IllegalStringEndQuote: return "Expected string end-quote.";
case ScannerError::IllegalNumberSeparator: return "Invalid use of number separator '_'.";
@ -844,7 +845,11 @@ Token Scanner::scanString(bool const _isUnicode)
// We are using a manual range and not isprint() to avoid
// any potential complications with locale.
if (!_isUnicode && (static_cast<unsigned>(c) <= 0x1f || static_cast<unsigned>(c) >= 0x7f))
{
if (m_kind == ScannerKind::Yul)
return setError(ScannerError::IllegalCharacterInString);
return setError(ScannerError::UnicodeCharacterInNonUnicodeString);
}
addLiteralChar(c);
}
}

View File

@ -81,6 +81,7 @@ enum class ScannerError
IllegalHexDigit,
IllegalCommentTerminator,
IllegalEscapeSequence,
UnicodeCharacterInNonUnicodeString,
IllegalCharacterInString,
IllegalStringEndQuote,
IllegalNumberSeparator,
@ -160,6 +161,8 @@ public:
/// Called by the parser during FunctionDefinition parsing to clear the current comment
void clearCurrentCommentLiteral() { m_skippedComments[Current].literal.clear(); }
ScannerKind scannerKind() const { return m_kind; }
///@}
///@{

View File

@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(string_nonprintable)
if (v == '\n' || v == '\v' || v == '\f' || v == '\r')
BOOST_CHECK_EQUAL(scanner.currentError(), ScannerError::IllegalStringEndQuote);
else
BOOST_CHECK_EQUAL(scanner.currentError(), ScannerError::IllegalCharacterInString);
BOOST_CHECK_EQUAL(scanner.currentError(),ScannerError::UnicodeCharacterInNonUnicodeString);
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "");
}
}

View File

@ -0,0 +1,7 @@
contract test {
function f() public pure returns (string memory) {
return ";
}
}
// ----
// ParserError 8936: (86-88): Invalid character in string. If you are trying to use Unicode characters, use a unicode"..." string literal.

View File

@ -4,4 +4,4 @@ contract test {
}
}
// ----
// ParserError 8936: (86-88): Invalid character in string.
// ParserError 8936: (86-88): Invalid character in string. If you are trying to use Unicode characters, use a unicode"..." string literal.