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
Preserve integer literal formatting in type hint #10818
Preserve integer literal formatting in type hint #10818
Conversation
22cfde8
to
a4273b1
Compare
Ready for review. @gasche and @Octachron, you have the context from #10767, perhaps you would be willing to take a look? |
Unsurprisingly, I prefer this implementation to #10767 . |
7113323
to
52b49bf
Compare
Thanks for the suggestions for improvement! All comments addressed, ready for another look. |
52b49bf
to
6b83fe0
Compare
The current state looks good to me, I am adding this PR to the post-freeze milestone. |
Awesome! I'll rebase on top of |
Note that you may want to wait before resolving conflicts, there is still many weeks left before the end of the freeze and Changes is quite conflict-prone. |
49ce179
to
0d4a77a
Compare
Cool, good to know. I only saw your message after rebasing, but I'll keep in mind that conflicts in Will I be notified when I should rebase to get the PR ready for merging? (This is my first contribution to the OCaml compiler.) |
Yes, I will notify you when the merge windows reopen. |
@curiousleo : the merge windows has reopened if you wish to rebase your PR it can be merged. |
0d4a77a
to
af9bf21
Compare
Rebase is 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.
The PR looks good to me: it improves error messages by doing less work overall.
af9bf21
to
0996df2
Compare
All review comments addressed. |
@Octachron thanks for taking a look! What's the next step? |
Octachron is on holidays today and tomorrow, I'll go ahead and merge if the CI is happy. |
Before: 1 | let _ = Int64.add 0xAA_BBl 2L;; ^^^^^^^^ Error: This expression has type int32 but an expression was expected of type int64 Hint: Did you mean `43707L'? After: 1 | let _ = Int64.add 0xAA_BBl 2L;; ^^^^^^^^ Error: This expression has type int32 but an expression was expected of type int64 Hint: Did you mean `0xAA_BBL'?
0996df2
to
ef84311
Compare
Thanks! I fixed the line length issue that was flagged by CI:
You may need to re-trigger CI so it runs on the new commit, sorry. |
Merged, thanks for your contribution and patience! |
My pleasure, thanks for the thoughtful reviews! |
Closes #10766, implementing "Proposal 1".
This is a more localised implementation than the implementation proposed in #10767, which changes
Asttype.constant
. It is based on this comment.User-visible changes
The goal of this PR is to preserve the original formatting of integer literals (
int32
,int64
andnativeint
) in the "Did you mean ...?" hint.Before
After
API changes
In
Typecore.error
:Pattern_type_clash
contains an optionalParsetree.pattern_desc
instead ofTypetree.pattern_desc
Expr_type_clash
contains an optionalParsetree.expression_desc
instead ofTypetree.expression_desc
In both cases, the description was and is only used to output the type hint. The difference is that the
Parsetree
descriptions contain the original formatting of the integer literal, but theTypetree
descriptions do not. Using theParsetree
descriptions instead of theTypetree
descriptions allows us to output the integer literals with their original formatting in the type hint.