-
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
Add C# 7.1 version to compiler #17894
Add C# 7.1 version to compiler #17894
Conversation
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
if (int.TryParse(version, NumberStyles.None, CultureInfo.InvariantCulture, out versionNumber) && | ||
versionNumber <= 6 && | ||
((LanguageVersion)versionNumber).IsValid()) | ||
if (int.TryParse(version, NumberStyles.None, CultureInfo.InvariantCulture, out int versionNumber) && versionNumber <= 7) |
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.
Do we now allow "07"? Consider reporting errors for leading zeros on any version number. #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.
@cston this wasn't introduced in this PR. In fact, I think RTM has this behaviour:
c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\csc.exe" a.cs /langversion:05
If you think this should be an error, we can change it in a later PR, but I wanted to merge this to unblock @AlekseyTs. Do I've a sign off? #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.
It was a minor point. Previously we allowed 7
but not 07
, now we allow 07
and 7.1
but not 07.1
. #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.
I agree. The weird format like 05
should no longer be allowed, starting with version 7. #Resolved
@@ -1355,7 +1357,7 @@ public void LanguageVersion_MapSpecifiedToEffectiveVersion() | |||
Assert.Equal(LanguageVersion.CSharp6, LanguageVersion.CSharp6.MapSpecifiedToEffectiveVersion()); | |||
Assert.Equal(LanguageVersion.CSharp7, LanguageVersion.CSharp7.MapSpecifiedToEffectiveVersion()); | |||
Assert.Equal(LanguageVersion.CSharp7, LanguageVersion.Default.MapSpecifiedToEffectiveVersion()); | |||
Assert.Equal(LanguageVersion.CSharp7, LanguageVersion.Latest.MapSpecifiedToEffectiveVersion()); |
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.
You're missing a test for CSharp7_1 #Resolved
@@ -1332,14 +1334,14 @@ public void LanguageVersionAdded_Canary() | |||
// - update the "UpgradeProject" codefixer |
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.
Did you update the UpgradeProject codefixer? We should add a diagnostic for "error CS80XX: Feature is not available in C# 7." and handle it in CSharpUpgradeProjectCodeFixProvider
.
This also mean updating the method for checking feature availability. #ByDesign
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.
Also, could you add a test for the LanguageVersionExtensionsInternal.GetErrorCode
method. It should loop over Enum.GetValues(typeof(LanguageVersion)).Cast<LanguageVersion>()
so that it breaks any time a new enum value is added.
#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.
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.
Yes, I realized that too. But I came up with a solution, by leveraging another feature that's useful for point releases, the #version
directive.
I have a PR almost ready: #17957
@jcouv had to merge this as soon as it got sign offs to unblock Aleksey. Will send another PR in the morning to cover the additional comments you left. #Resolved |
No problem. |
@@ -2690,7 +2690,7 @@ A catch() block after a catch (System.Exception e) block can catch non-CLS excep | |||
<value>This warning occurs if the assembly attributes AssemblyKeyFileAttribute or AssemblyKeyNameAttribute found in source conflict with the /keyfile or /keycontainer command line option or key file name or key container specified in the Project Properties.</value> | |||
</data> | |||
<data name="ERR_BadCompatMode" xml:space="preserve"> | |||
<value>Invalid option '{0}' for /langversion; must be ISO-1, ISO-2, Default or an integer in range 1 to 7.</value> | |||
<value>Invalid option '{0}' for /langversion; must be ISO-1, ISO-2, Default, Latest or a valid version in range 1 to 7.1.</value> |
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 wonder if we should enumerate the valid versions in the message (1, 2, 3, 4, 5, 6, 7, 7.1) #ByDesign
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.
Wouldn't it be too long? Consider in a couple of point releases:
Invalid option '{0}' for /langversion; must be ISO-1, ISO-2, Default, Latest, 1, 2, 3, 4, 5, 6, 7, 7,1, 7.2, 8.
I'd claim that people calling csc from command line already know what they're doing (and they don't need to know which C# versions were shipped), VS UI or first time users who would normally use VS project dialogs to enumerate available versions.
In reply to: 106479809 [](ancestors = 106479809)
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.
Ok. Let's leave as-is. #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.
Added a couple suggestions.
@@ -5032,4 +5032,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ | |||
<data name="ERR_InvalidPreprocessingSymbol" xml:space="preserve"> | |||
<value>Invalid name for a preprocessing symbol; '{0}' is not a valid identifier</value> | |||
</data> | |||
<data name="ERR_FeatureNotAvailableInVersion7_1" xml:space="preserve"> | |||
<value>Feature '{0}' is not available in C# 7.1. Please use language version {1} or greater.</value> |
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.
Nit: two spaces after 7.1. #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.
Paste issue from similar messages :) will fix all of them now.
In reply to: 106479940 [](ancestors = 106479940)
@@ -212,6 +229,7 @@ public static LanguageVersion MapSpecifiedToEffectiveVersion(this LanguageVersio | |||
switch (version) | |||
{ | |||
case LanguageVersion.Latest: | |||
return LanguageVersion.CSharp7_1; |
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 wonder if we could make this code invariant so it doesn't have to be updated with every point release. Maybe we just return the largest enum entry except for LanguageVersion.Latest
. #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.
I think this file is very easy to edit. After the recent rectoring (by you), all our version work is done here, and adding a new version is simply editing 3~4 lines in that file, plus the required testing.
In reply to: 106483298 [](ancestors = 106483298)
This PR implements parts of #17173 #Resolved |
@OmarTawfik As a side note, I noticed that you merge your PRs, rather than squash them. I find that the history is more readable with squashed PRs (it avoids commits like "PR feedback", or "fix" making it into the github history). For your consideration :-) #Resolved |
Thanks :) In reply to: 287243222 [](ancestors = 287243222) |
* Responded to PR comments on #17894 * Added more tests, and supporting 1.0, 2.0, 3.0, etc... versions * Clean up
cc @AlekseyTs @jcouv @dotnet/roslyn-compiler
Contributes to #17173