-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Allow digit separator after base specifier #20449
Conversation
a7227bc
to
8d7fb2b
Compare
Ping @gafter since he's the LDM champion for that proposal. |
@gafter Did we get approval from LDM on this already? |
Neal confirmed that LDM approved the feature. Let's go ahead with review. |
underscoreInWrongPlace = true; | ||
if (isHex || isBinary) | ||
{ | ||
// TODO(leading-digit-separator): check feature flag |
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.
We don't let new TODOs into the master branch.
Blockers should be addressed. Non-blockers should be tracked with a github issue.
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.
Please address the TODOs (ie adding a feature flag). Thanks
failure: Microsoft.CodeAnalysis.Editor.UnitTests.Structure.StructureTaggerTests.OutliningTaggerTooltipText (details) FYI @dotnet/roslyn-infrastructure |
@@ -2616,6 +2620,52 @@ public void TestNumericWithUnderscoresWithoutFeatureFlag() | |||
|
|||
[Fact] | |||
[Trait("Feature", "Literals")] | |||
public void TestNumericWithLeadingUnderscores() | |||
{ | |||
var text = "0x_A"; |
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.
Please test with multiple underscores. @gafter can confirm expected language/spec behavior. #Resolved
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.
underscoreInWrongPlace = true; | ||
if (isHex || isBinary) | ||
{ | ||
CheckFeatureAvailability(MessageID.IDS_FeatureLeadingDigitSeparator); |
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.
Should lastCharWasUnderscore be set to true?
Test 0x_1 with language version prior to IDS_FeatureDigitSeparator. I think usedUnderscore should be left unset (no need for cascading feature error)
Assert.Equal(SyntaxKind.IntegerLiteralToken, tk.Kind) | ||
Assert.Equal(LiteralBase.Octal, tk.GetBase()) | ||
Assert.Equal(&O1, tk.Value) | ||
Assert.Equal(" &O_1 ", tk.ToFullString()) |
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 test suggestions for VB. Thanks #Resolved
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.
Ping the roslyn-compiler alias for review when feedback addressed. I will be away for some time.
Thanks
@dotnet/roslyn-compiler for review (community contribution, approved by LDM already). Thanks |
CheckFeatureAvailability(MessageID.IDS_FeatureLeadingDigitSeparator); | ||
// No need for cascading feature error | ||
usedUnderscore = false; | ||
} |
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.
Consider switching order: if (firstCharWasUnderscore) { ... } else if (lastCharWasUnderscore) { ... }
.
#Resolved
@@ -2695,17 +2772,6 @@ public void TestNumericWithBadUnderscores() | |||
Assert.Equal("error CS1013: Invalid number", errors[0].ToString(EnsureEnglishUICulture.PreferredOrNull)); | |||
Assert.Equal(text, token.Text); |
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.
Please add tests for 1E+_2
, 1E-_2
, and 1E_
. #Resolved
ece5c60
to
a1395e3
Compare
@@ -1695,7 +1696,10 @@ FullWidthRepeat: | |||
IntegerLiteralStart = Here | |||
Base = LiteralBase.Hexadecimal | |||
|
|||
UnderscoreInWrongPlace = (CanGet(Here) AndAlso Peek(Here) = "_"c) | |||
If (CanGet(Here) AndAlso Peek(Here) = "_"c) Then |
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.
Unnecessary parentheses around entire Boolean expression, here and below.
@@ -1673,6 +1673,7 @@ FullWidthRepeat: | |||
Dim IntegerLiteralStart As Integer | |||
Dim UnderscoreInWrongPlace As Boolean |
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.
Consider assigning False
here since the value is not explicitly initialized any more. Also, there are several cases below where the value is assigned UnderscoreInWrongPlace = UnderscoreInWrongPlace Or (Peek(Here - 1) = "_"c)
where UnderscoreInWrongPlace
is initially False
. (In short, the UnderscoreInWrongPlace Or
is unnecessary.)
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.
In short, the UnderscoreInWrongPlace Or is unnecessary.
Yeah, crossed my mind, shouldn't VB flag those cases in the first place?
End If | ||
|
||
If UnderscoreUsed Then | ||
ElseIf LeadingUnderscoreUsed Then |
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.
With ElseIf
rather than If
we're no longer reporting both overflow and feature-not-available errors (e.g.: compiling Dim x = &H123_456_789_ABC_DEF_123
with -langversion:14
). We should report both errors in such cases since the errors are independent.
a1395e3
to
66f98ba
Compare
66f98ba
to
4bad4d7
Compare
@@ -2085,13 +2095,16 @@ FullWidthRepeat2: | |||
|
|||
If Overflows Then |
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.
FYI The order is now in sync with C#, an interesting case is an overflowing integer with a trailing underscore which gives 1 and 2 errors in VB and C# respectively. This is now fixed.
Any other case that needs to be verified here?
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.
LGTM Thanks
Ping @cston
Merged. Thanks @alrz For cleaner history, it would have been even better to rebase and squash your branch, rather than merging latest master. But given that the PR only has a couple of commit, it's not crucial (I merged without squashing, because of the merge from master). |
Proposal: dotnet/csharplang#65