-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[move-compiler-v2] Print a better error message for a string without b or x #14687
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #14687 +/- ##
=========================================
- Coverage 59.8% 59.8% -0.1%
=========================================
Files 851 851
Lines 207246 207266 +20
=========================================
+ Hits 124055 124056 +1
- Misses 83191 83210 +19 ☔ View full report in Codecov by Sentry. |
40ddded
to
fd0493f
Compare
┌─ tests/move_check/parser/constants_simple.move:16:29 | ||
│ | ||
16 │ const C12: vector<u8> = "<empty>"; | ||
│ ^ String literal must begin with b" (for a byte string) or h" (for a hex string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should break this test up, so that this new blocking (parse) error does not shadow the compile errors being showcased before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
let loc = make_loc(file_hash, start_offset, start_offset); | ||
return Err(Box::new(diag!( | ||
Syntax::InvalidByteString, | ||
(loc, "String literal must begin with b\" (for a byte string) or h\" (for a hex string)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hex strings are x"255"
according to the Move book, not h"255"
. Fix here if this was a typo, else, we need to fix the Move book to say we also allow h"255"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
const C10: vector<u8> = b"<empty>"; | ||
const C11: vector<u8> = x"deadbeef"; | ||
const C12: vector<u8> = "<empty>"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also add one case of strings with some escape characters, e.g., "\"\x48"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did better than that, I added a case with a non-UTF character. We'll see how portable that one is.
│ │ | ||
│ Invalid call or operation in constant | ||
error: invalid byte string | ||
┌─ tests/folding/constants_simple.move:16:29 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as before: split test to retain old error messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
fd0493f
to
b9c9bff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for rebase, but PTAL.
|
||
const C10: vector<u8> = b"<empty>"; | ||
const C11: vector<u8> = x"deadbeef"; | ||
const C12: vector<u8> = "<empty>"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did better than that, I added a case with a non-UTF character. We'll see how portable that one is.
┌─ tests/move_check/parser/constants_simple.move:16:29 | ||
│ | ||
16 │ const C12: vector<u8> = "<empty>"; | ||
│ ^ String literal must begin with b" (for a byte string) or h" (for a hex string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
let loc = make_loc(file_hash, start_offset, start_offset); | ||
return Err(Box::new(diag!( | ||
Syntax::InvalidByteString, | ||
(loc, "String literal must begin with b\" (for a byte string) or h\" (for a hex string)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
│ │ | ||
│ Invalid call or operation in constant | ||
error: invalid byte string | ||
┌─ tests/folding/constants_simple.move:16:29 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
0d30d79
to
8fb3bfb
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
8fb3bfb
to
fb0b705
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ Forge suite
|
✅ Forge suite
|
✅ Forge suite
|
Description
Fixes #14364.
Type of Change
Which Components or Systems Does This Change Impact?
How Has This Been Tested?
Run by hand.
Key Areas to Review
There doesn't seem to be any way to recover from this sort of error. But at least we can help inform people when
they type "foo" instead of b"foo".
Checklist