Skip to content
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

Merged
merged 6 commits into from
Aug 30, 2017

Conversation

alrz
Copy link
Member

@alrz alrz commented Jun 26, 2017

@alrz alrz force-pushed the features/leading-digit-separator branch 2 times, most recently from a7227bc to 8d7fb2b Compare June 26, 2017 18:25
@jcouv
Copy link
Member

jcouv commented Jun 29, 2017

Ping @gafter since he's the LDM champion for that proposal.

@jcouv jcouv added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Aug 1, 2017
@jcouv
Copy link
Member

jcouv commented Aug 1, 2017

@gafter Did we get approval from LDM on this already?

@jcouv
Copy link
Member

jcouv commented Aug 4, 2017

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
Copy link
Member

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.

jcouv
jcouv previously requested changes Aug 4, 2017
Copy link
Member

@jcouv jcouv left a 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

@alrz
Copy link
Member Author

alrz commented Aug 7, 2017

failure: Microsoft.CodeAnalysis.Editor.UnitTests.Structure.StructureTaggerTests.OutliningTaggerTooltipText (details)

FYI @dotnet/roslyn-infrastructure

@jcouv
Copy link
Member

jcouv commented Aug 7, 2017

    // Allows underscores in integers, except at beginning and end

Please update comment #Resolved


Refers to: src/Compilers/CSharp/Portable/Parser/Lexer.cs:935 in ee697a5. [](commit_id = ee697a5, deletion_comment = False)

@@ -2616,6 +2620,52 @@ public void TestNumericWithUnderscoresWithoutFeatureFlag()

[Fact]
[Trait("Feature", "Literals")]
public void TestNumericWithLeadingUnderscores()
{
var text = "0x_A";
Copy link
Member

@jcouv jcouv Aug 7, 2017

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also test for trailing underscore: "0x_"


In reply to: 131779530 [](ancestors = 131779530)

underscoreInWrongPlace = true;
if (isHex || isBinary)
{
CheckFeatureAvailability(MessageID.IDS_FeatureLeadingDigitSeparator);
Copy link
Member

@jcouv jcouv Aug 7, 2017

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())
Copy link
Member

@jcouv jcouv Aug 7, 2017

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

Copy link
Member

@jcouv jcouv left a 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

@jcouv jcouv self-assigned this Aug 9, 2017
@alrz
Copy link
Member Author

alrz commented Aug 10, 2017

@jcouv I can't tag @dotnet/roslyn-compiler. also tagging @gafter for review.

@jcouv
Copy link
Member

jcouv commented Aug 10, 2017

@dotnet/roslyn-compiler for review (community contribution, approved by LDM already). Thanks

@jcouv jcouv dismissed their stale review August 10, 2017 20:39

Out of office

CheckFeatureAvailability(MessageID.IDS_FeatureLeadingDigitSeparator);
// No need for cascading feature error
usedUnderscore = false;
}
Copy link
Member

@cston cston Aug 11, 2017

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);
Copy link
Member

@cston cston Aug 11, 2017

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

@alrz alrz force-pushed the features/leading-digit-separator branch from ece5c60 to a1395e3 Compare August 11, 2017 16:19
@@ -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
Copy link
Member

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
Copy link
Member

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.)

Copy link
Member Author

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
Copy link
Member

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.

@alrz alrz force-pushed the features/leading-digit-separator branch from a1395e3 to 66f98ba Compare August 11, 2017 18:40
@alrz alrz force-pushed the features/leading-digit-separator branch from 66f98ba to 4bad4d7 Compare August 11, 2017 18:56
@@ -2085,13 +2095,16 @@ FullWidthRepeat2:

If Overflows Then
Copy link
Member Author

@alrz alrz Aug 11, 2017

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?

Copy link
Member

@jcouv jcouv left a 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

@jcouv jcouv merged commit 7dd7af9 into dotnet:master Aug 30, 2017
@jcouv
Copy link
Member

jcouv commented Aug 30, 2017

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).

@alrz alrz deleted the features/leading-digit-separator branch August 30, 2017 21:36
@sharwell sharwell added Community The pull request was submitted by a contributor who is not a Microsoft employee. and removed Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Aug 31, 2017
@jcouv jcouv added this to the 15.5 milestone Sep 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Area-Language Design cla-already-signed Community The pull request was submitted by a contributor who is not a Microsoft employee. Language-C#
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants