Skip to content

Commit c21265f

Browse files
SamuelOsewacameel
authored andcommitted
Changed error message for for Unicode character in non-unicode string literal
Co-authored-by: Kamil Śliwak <[email protected]>
1 parent 9542e46 commit c21265f

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

liblangutil/Scanner.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ string to_string(ScannerError _errorCode)
7676
case ScannerError::IllegalHexDigit: return "Hexadecimal digit missing or invalid.";
7777
case ScannerError::IllegalCommentTerminator: return "Expected multi-line comment-terminator.";
7878
case ScannerError::IllegalEscapeSequence: return "Invalid escape sequence.";
79+
case ScannerError::UnicodeCharacterInNonUnicodeString: return "Invalid character in string. If you are trying to use Unicode characters, use a unicode\"...\" string literal.";
7980
case ScannerError::IllegalCharacterInString: return "Invalid character in string.";
8081
case ScannerError::IllegalStringEndQuote: return "Expected string end-quote.";
8182
case ScannerError::IllegalNumberSeparator: return "Invalid use of number separator '_'.";
@@ -844,7 +845,11 @@ Token Scanner::scanString(bool const _isUnicode)
844845
// We are using a manual range and not isprint() to avoid
845846
// any potential complications with locale.
846847
if (!_isUnicode && (static_cast<unsigned>(c) <= 0x1f || static_cast<unsigned>(c) >= 0x7f))
847-
return setError(ScannerError::IllegalCharacterInString);
848+
{
849+
if (m_kind == ScannerKind::Yul)
850+
return setError(ScannerError::IllegalCharacterInString);
851+
return setError(ScannerError::UnicodeCharacterInNonUnicodeString);
852+
}
848853
addLiteralChar(c);
849854
}
850855
}

liblangutil/Scanner.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ enum class ScannerError
8181
IllegalHexDigit,
8282
IllegalCommentTerminator,
8383
IllegalEscapeSequence,
84+
UnicodeCharacterInNonUnicodeString,
8485
IllegalCharacterInString,
8586
IllegalStringEndQuote,
8687
IllegalNumberSeparator,
@@ -160,6 +161,8 @@ class Scanner
160161
/// Called by the parser during FunctionDefinition parsing to clear the current comment
161162
void clearCurrentCommentLiteral() { m_skippedComments[Current].literal.clear(); }
162163

164+
ScannerKind scannerKind() const { return m_kind; }
165+
163166
///@}
164167

165168
///@{

test/liblangutil/Scanner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(string_nonprintable)
123123
if (v == '\n' || v == '\v' || v == '\f' || v == '\r')
124124
BOOST_CHECK_EQUAL(scanner.currentError(), ScannerError::IllegalStringEndQuote);
125125
else
126-
BOOST_CHECK_EQUAL(scanner.currentError(), ScannerError::IllegalCharacterInString);
126+
BOOST_CHECK_EQUAL(scanner.currentError(),ScannerError::UnicodeCharacterInNonUnicodeString);
127127
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "");
128128
}
129129
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
contract test {
2+
function f() public pure returns (string memory) {
3+
return ";
4+
}
5+
}
6+
// ----
7+
// ParserError 8936: (86-88): Invalid character in string. If you are trying to use Unicode characters, use a unicode"..." string literal.

test/libsolidity/syntaxTests/string/string_unicode_without_prefix.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ contract test {
44
}
55
}
66
// ----
7-
// ParserError 8936: (86-88): Invalid character in string.
7+
// ParserError 8936: (86-88): Invalid character in string. If you are trying to use Unicode characters, use a unicode"..." string literal.

0 commit comments

Comments
 (0)