Merge pull request #9867 from ethereum/string-literals

More clear error messages with converting (hex) string literals
This commit is contained in:
chriseth
2020-09-24 12:49:46 +02:00
committed by GitHub
14 changed files with 41 additions and 24 deletions
+1 -1
View File
@@ -86,7 +86,7 @@
"typeDescriptions":
{
"typeIdentifier": "t_stringliteral_8b1a944cf13a9a1c08facb2c9e98623ef3254d2ddb48113885c3e8e97fec8db9",
"typeString": "literal_string (contains invalid UTF-8 sequence at position 0)"
"typeString": "literal_string hex\"ff\""
}
},
"nodeType": "VariableDeclarationStatement",
@@ -131,7 +131,7 @@
"isPure": true,
"lValueRequested": false,
"token": "hexString",
"type": "literal_string (contains invalid UTF-8 sequence at position 0)"
"type": "literal_string hex\"ff\""
},
"id": 5,
"name": "Literal",
+1 -1
View File
@@ -86,7 +86,7 @@
"typeDescriptions":
{
"typeIdentifier": "t_stringliteral_cd7a99177cebb3d14b8cc54e313dbf76867c71cd6fbb9a33ce3870dc80e9992b",
"typeString": "literal_string \"Hello \ud83d\ude03\""
"typeString": "literal_string hex\"48656c6c6f20f09f9883\""
},
"value": "Hello \ud83d\ude03"
},
+1 -1
View File
@@ -131,7 +131,7 @@
"isPure": true,
"lValueRequested": false,
"token": "unicodeString",
"type": "literal_string \"Hello \ud83d\ude03\"",
"type": "literal_string hex\"48656c6c6f20f09f9883\"",
"value": "Hello \ud83d\ude03"
},
"id": 5,
@@ -2,4 +2,4 @@ contract C {
string s = string("\xa0\x00");
}
// ----
// TypeError 9640: (28-46): Explicit type conversion not allowed from "literal_string (contains invalid UTF-8 sequence at position 0)" to "string memory".
// TypeError 9640: (28-46): Explicit type conversion not allowed from "literal_string hex"a000"" to "string memory". Contains invalid UTF-8 sequence at position 0.
@@ -2,4 +2,4 @@ contract C {
string s = hex"a000";
}
// ----
// TypeError 7407: (28-37): Type literal_string (contains invalid UTF-8 sequence at position 0) is not implicitly convertible to expected type string storage ref.
// TypeError 7407: (28-37): Type literal_string hex"a000" is not implicitly convertible to expected type string storage ref. Contains invalid UTF-8 sequence at position 0.
@@ -2,4 +2,4 @@ contract C {
string s = "\xa0\x00";
}
// ----
// TypeError 7407: (28-38): Type literal_string (contains invalid UTF-8 sequence at position 0) is not implicitly convertible to expected type string storage ref.
// TypeError 7407: (28-38): Type literal_string hex"a000" is not implicitly convertible to expected type string storage ref. Contains invalid UTF-8 sequence at position 0.
@@ -2,5 +2,5 @@ contract C {
string s = unicode"À";
}
// ----
// SyntaxError 8452: (28-38): Invalid UTF-8 sequence found
// TypeError 7407: (28-38): Type literal_string (contains invalid UTF-8 sequence at position 0) is not implicitly convertible to expected type string storage ref.
// SyntaxError 8452: (28-38): Contains invalid UTF-8 sequence at position 0.
// TypeError 7407: (28-38): Type literal_string hex"c0" is not implicitly convertible to expected type string storage ref. Contains invalid UTF-8 sequence at position 0.
@@ -4,4 +4,4 @@ contract test {
}
}
// ----
// TypeError 6359: (86-92): Return argument type literal_string (contains invalid UTF-8 sequence at position 0) is not implicitly convertible to expected type (type of first return variable) string memory.
// TypeError 6359: (86-92): Return argument type literal_string hex"c1" is not implicitly convertible to expected type (type of first return variable) string memory. Contains invalid UTF-8 sequence at position 0.
@@ -4,4 +4,4 @@ contract C {
}
}
// ----
// TypeError 9640: (76-95): Explicit type conversion not allowed from "literal_string "4V"" to "bytes2". Literal is larger than the type.
// TypeError 9640: (76-95): Explicit type conversion not allowed from "literal_string hex"123456"" to "bytes2". Literal is larger than the type.
@@ -14,7 +14,7 @@ contract C {
}
}
// ----
// TypeError 9640: (92-109): Explicit type conversion not allowed from "literal_string "4"" to "bytes1". Literal is larger than the type.
// TypeError 9640: (198-217): Explicit type conversion not allowed from "literal_string "4V"" to "bytes2". Literal is larger than the type.
// TypeError 9640: (310-331): Explicit type conversion not allowed from "literal_string "4Vx"" to "bytes3". Literal is larger than the type.
// TypeError 9640: (430-453): Explicit type conversion not allowed from "literal_string (contains invalid UTF-8 sequence at position 4)" to "bytes4". Literal is larger than the type.
// TypeError 9640: (92-109): Explicit type conversion not allowed from "literal_string hex"1234"" to "bytes1". Literal is larger than the type.
// TypeError 9640: (198-217): Explicit type conversion not allowed from "literal_string hex"123456"" to "bytes2". Literal is larger than the type.
// TypeError 9640: (310-331): Explicit type conversion not allowed from "literal_string hex"12345678"" to "bytes3". Literal is larger than the type.
// TypeError 9640: (430-453): Explicit type conversion not allowed from "literal_string hex"1234567890"" to "bytes4". Literal is larger than the type.