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

Add LangVersion 7.2 for C# #19846

Merged
merged 1 commit into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/compilers/CSharp/CommandLine.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
| `/checked`{`+`|`-`} | Generate overflow checks
| `/unsafe`{`+`|`-`} | Allow 'unsafe' code
| `/define:`*symbol list* | Define conditional compilation symbol(s) (Short form: `/d`)
| `/langversion`:*string* | Specify language version mode: `ISO-1`, `ISO-2`, `3`, `4`, `5`, `6`, `7`, `7.1`, `Default` (latest major version), or `Latest` (latest version, including minor versions)
| `/langversion`:*string* | Specify language version mode: `ISO-1`, `ISO-2`, `3`, `4`, `5`, `6`, `7`, `7.1`, `7.2`, `Default` (latest major version), or `Latest` (latest version, including minor versions)
| **SECURITY**
| `/delaysign`{`+`|`-`} | Delay-sign the assembly using only the public portion of the strong name key
| `/keyfile:`*file* | Specify a strong name key file
Expand Down
11 changes: 10 additions & 1 deletion src/Compilers/CSharp/Portable/CSharpResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2705,7 +2705,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>
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to do a string search/replace over the modified error strings in the tests project, to make sure that the error comments in tests are updated as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

The resource strings I modified do not exist in tests. But I do have a test to extract the versions that appear on that line and verifies that it's complete: https://github.com/dotnet/roslyn/pull/19113/files#diff-492ea20f4ae7785ece041adfb13b4e7d

<data name="ERR_BadCompatMode" xml:space="preserve">
<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>
<value>Invalid option '{0}' for /langversion; must be ISO-1, ISO-2, Default, Latest or a valid version in range 1 to 7.2.</value>
</data>
<data name="ERR_DelegateOnConditional" xml:space="preserve">
<value>Cannot create delegate with '{0}' because it or a method it overrides has a Conditional attribute</value>
Expand Down Expand Up @@ -4472,7 +4472,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
/define:&lt;symbol list&gt; Define conditional compilation symbol(s) (Short
form: /d)
/langversion:&lt;string&gt; Specify language version mode: ISO-1, ISO-2, 3,
4, 5, 6, 7.0, 7.1, Default, or Latest
4, 5, 6, 7.0, 7.1, 7.2, Default, or Latest

- SECURITY -
/delaysign[+|-] Delay-sign the assembly using only the public
Expand Down Expand Up @@ -5048,6 +5048,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<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>
</data>
<data name="ERR_FeatureNotAvailableInVersion7_2" xml:space="preserve">
<value>Feature '{0}' is not available in C# 7.2. Please use language version {1} or greater.</value>
</data>
<data name="ERR_LanguageVersionCannotHaveLeadingZeroes" xml:space="preserve">
<value>Specified language version '{0}' cannot have leading zeroes</value>
</data>
Expand Down
4 changes: 4 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1488,5 +1488,9 @@ internal enum ErrorCode
ERR_PatternWrongGenericTypeInVersion = 8314,

#endregion diagnostics introduced for C# 7.1

#region diagnostics introduced for C# 7.2
ERR_FeatureNotAvailableInVersion7_2 = 8320,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is going into master, and there are no concers of conflicts, we can just use 8315?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is going into 15.6 branch. 7.1 is not closed yet, so I left some buffer. (Just today I had to use a new error code for a 7.1 fix).

#endregion diagnostics introduced for C# 7.2
}
}
16 changes: 15 additions & 1 deletion src/Compilers/CSharp/Portable/LanguageVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public enum LanguageVersion
/// </summary>
CSharp7_1 = 701,

/// <summary>
/// C# language version 7.2
/// </summary>
CSharp7_2 = 702,

/// <summary>
/// The latest version of the language supported.
/// </summary>
Expand All @@ -94,6 +99,7 @@ internal static bool IsValid(this LanguageVersion value)
case LanguageVersion.CSharp6:
case LanguageVersion.CSharp7:
case LanguageVersion.CSharp7_1:
case LanguageVersion.CSharp7_2:
return true;
}

Expand All @@ -120,6 +126,8 @@ internal static ErrorCode GetErrorCode(this LanguageVersion version)
return ErrorCode.ERR_FeatureNotAvailableInVersion7;
case LanguageVersion.CSharp7_1:
return ErrorCode.ERR_FeatureNotAvailableInVersion7_1;
case LanguageVersion.CSharp7_2:
return ErrorCode.ERR_FeatureNotAvailableInVersion7_2;
Copy link
Contributor

@AlekseyTs AlekseyTs May 30, 2017

Choose a reason for hiding this comment

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

ERR_FeatureNotAvailableInVersion7_2 [](start = 37, length = 35)

What is the benefit of having an error code per version? It looks like we could easily use one parameterized error message. In fact, for some features in some situations we do this (use parameterized error message) when these errors cannot be used. #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd raised that question before. Someone (maybe Vlad or Neal) had previously suggested this helps telemetry.
Filed follow-up issue #19871

Copy link
Member Author

Choose a reason for hiding this comment

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

Dug up the telemetry comment (from Cyrus): #17435 (comment)

@CyrusNajmabadi Could you expand on why separate error codes and diagnostics is preferable for LanguageVersion, rather than one parameterized set?

Copy link
Member

Choose a reason for hiding this comment

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

My telemetry comment was about you instantiating SolutionChangeAction directly. You need to create a subclass of that.

I do not care if you use a single diagnostic ID or different diagnostic IDs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the clarification.

I have a follow-up issue to use a generic diagnostic ID.
@AlekseyTs Any other feedback?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think @gafter was the person who pointed out the telemetry issue to me. He can confirm if that is still an issue or not.

default:
throw ExceptionUtilities.UnexpectedValue(version);
}
Expand Down Expand Up @@ -164,6 +172,8 @@ public static string ToDisplayString(this LanguageVersion version)
return "7.0";
case LanguageVersion.CSharp7_1:
return "7.1";
case LanguageVersion.CSharp7_2:
return "7.2";
case LanguageVersion.Default:
return "default";
case LanguageVersion.Latest:
Expand Down Expand Up @@ -235,6 +245,10 @@ public static bool TryParse(this string version, out LanguageVersion result)
result = LanguageVersion.CSharp7_1;
return true;

case "7.2":
result = LanguageVersion.CSharp7_2;
return true;

default:
result = LanguageVersion.Default;
return false;
Expand All @@ -249,7 +263,7 @@ public static LanguageVersion MapSpecifiedToEffectiveVersion(this LanguageVersio
switch (version)
{
case LanguageVersion.Latest:
return LanguageVersion.CSharp7_1;
return LanguageVersion.CSharp7_2;
case LanguageVersion.Default:
return LanguageVersion.CSharp7;
default:
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp7_1 = 701 -> Microsoft.CodeAnalysis.CSharp.LanguageVersion
Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp7_2 = 702 -> Microsoft.CodeAnalysis.CSharp.LanguageVersion
Microsoft.CodeAnalysis.CSharp.LanguageVersionFacts
Microsoft.CodeAnalysis.CSharp.SyntaxKind.ConflictMarkerTrivia = 8564 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
Microsoft.CodeAnalysis.CSharp.SyntaxKind.DefaultLiteralExpression = 8755 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
Expand Down
9 changes: 6 additions & 3 deletions src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ public void LanguageVersionAdded_Canary()
// - update the IDE drop-down for selecting Language Version
// - update all the tests that call this canary
// - update the command-line documentation (CommandLine.md)
AssertEx.SetEqual(new[] { "default", "1", "2", "3", "4", "5", "6", "7.0", "7.1", "latest" },
AssertEx.SetEqual(new[] { "default", "1", "2", "3", "4", "5", "6", "7.0", "7.1", "7.2", "latest" },
Enum.GetValues(typeof(LanguageVersion)).Cast<LanguageVersion>().Select(v => v.ToDisplayString()));
// For minor versions, the format should be "x.y", such as "7.1"
}
Expand All @@ -1325,7 +1325,8 @@ public void LanguageVersion_GetErrorCode()
ErrorCode.ERR_FeatureNotAvailableInVersion5,
ErrorCode.ERR_FeatureNotAvailableInVersion6,
ErrorCode.ERR_FeatureNotAvailableInVersion7,
ErrorCode.ERR_FeatureNotAvailableInVersion7_1
ErrorCode.ERR_FeatureNotAvailableInVersion7_1,
ErrorCode.ERR_FeatureNotAvailableInVersion7_2
};

AssertEx.SetEqual(versions, errorCodes);
Expand All @@ -1345,9 +1346,10 @@ public void LanguageVersion_MapSpecifiedToEffectiveVersion()
Assert.Equal(LanguageVersion.CSharp6, LanguageVersion.CSharp6.MapSpecifiedToEffectiveVersion());
Assert.Equal(LanguageVersion.CSharp7, LanguageVersion.CSharp7.MapSpecifiedToEffectiveVersion());
Assert.Equal(LanguageVersion.CSharp7_1, LanguageVersion.CSharp7_1.MapSpecifiedToEffectiveVersion());
Assert.Equal(LanguageVersion.CSharp7_2, LanguageVersion.CSharp7_2.MapSpecifiedToEffectiveVersion());

Assert.Equal(LanguageVersion.CSharp7, LanguageVersion.Default.MapSpecifiedToEffectiveVersion());
Assert.Equal(LanguageVersion.CSharp7_1, LanguageVersion.Latest.MapSpecifiedToEffectiveVersion());
Assert.Equal(LanguageVersion.CSharp7_2, LanguageVersion.Latest.MapSpecifiedToEffectiveVersion());

// The canary check is a reminder that this test needs to be updated when a language version is added
LanguageVersionAdded_Canary();
Expand All @@ -1374,6 +1376,7 @@ public void LanguageVersion_MapSpecifiedToEffectiveVersion()
InlineData("7.0", true, LanguageVersion.CSharp7),
InlineData("07", false, LanguageVersion.Default),
InlineData("7.1", true, LanguageVersion.CSharp7_1),
InlineData("7.2", true, LanguageVersion.CSharp7_2),
InlineData("07.1", false, LanguageVersion.Default),
InlineData("default", true, LanguageVersion.Default),
InlineData("latest", true, LanguageVersion.Latest),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics.Async
{
[Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
public partial class UpgradeProjectTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
{
internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace)
Expand Down Expand Up @@ -38,7 +39,7 @@ private async Task TestLanguageVersionUpgradedAsync(
await TestAsync(initialMarkup, initialMarkup, parseOptions); // no change to markup
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task UpgradeProjectFromCSharp6ToDefault()
{
await TestLanguageVersionUpgradedAsync(
Expand All @@ -54,7 +55,7 @@ void A()
new CSharpParseOptions(LanguageVersion.CSharp6));
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task UpgradeProjectFromCSharp6ToCSharp7()
{
await TestLanguageVersionUpgradedAsync(
Expand All @@ -71,7 +72,7 @@ void A()
index: 1);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task UpgradeProjectFromCSharp5ToCSharp6()
{
await TestLanguageVersionUpgradedAsync(
Expand All @@ -88,7 +89,7 @@ void A()
index: 1);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task UpgradeProjectFromCSharp4ToCSharp5()
{
await TestLanguageVersionUpgradedAsync(
Expand All @@ -105,7 +106,7 @@ void A()
index: 1);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task UpgradeProjectFromCSharp7ToLatest()
{
await TestLanguageVersionUpgradedAsync(
Expand All @@ -118,7 +119,7 @@ class Program
new CSharpParseOptions(LanguageVersion.CSharp7));
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task UpgradeProjectFromCSharp7ToLatest_TriggeredByInferredTupleNames()
{
await TestLanguageVersionUpgradedAsync(
Expand Down Expand Up @@ -152,7 +153,7 @@ public ValueTuple(T1 item1, T2 item2)
new CSharpParseOptions(LanguageVersion.CSharp7));
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task UpgradeProjectFromCSharp7_1ToLatest()
{
await TestLanguageVersionUpgradedAsync(
Expand All @@ -165,7 +166,20 @@ class Program
new CSharpParseOptions(LanguageVersion.CSharp7_1));
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task UpgradeProjectFromCSharp7_2ToLatest()
{
await TestLanguageVersionUpgradedAsync(
@"
class Program
{
#error version:[|7.2|]
}",
LanguageVersion.Latest,
new CSharpParseOptions(LanguageVersion.CSharp7_2));
}

[Fact]
public async Task UpgradeProjectFromCSharp7ToCSharp7_1()
{
await TestLanguageVersionUpgradedAsync(
Expand All @@ -179,7 +193,7 @@ class Program
index: 1);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task UpgradeProjectFromCSharp7ToCSharp7_1_B()
{
await TestLanguageVersionUpgradedAsync(
Expand All @@ -198,7 +212,7 @@ public static void M<T>(T x) where T: Base
index: 1);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task UpgradeAllProjectsToDefault()
{
await TestLanguageVersionUpgradedAsync(
Expand Down Expand Up @@ -229,7 +243,7 @@ void A()

}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task UpgradeAllProjectsToCSharp7()
{
await TestLanguageVersionUpgradedAsync(
Expand Down Expand Up @@ -259,7 +273,7 @@ void A()
index: 2);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task ListAllSuggestions()
{
await TestExactActionSetOfferedAsync(
Expand Down Expand Up @@ -289,7 +303,7 @@ void A()
});
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task FixAllProjectsNotOffered()
{
await TestExactActionSetOfferedAsync(
Expand All @@ -315,7 +329,7 @@ void A()
});
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task OnlyOfferFixAllProjectsToCSharp7WhenApplicable()
{
await TestExactActionSetOfferedAsync(
Expand Down Expand Up @@ -344,7 +358,7 @@ void A()
});
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
[Fact]
public async Task OnlyOfferFixAllProjectsToDefaultWhenApplicable()
{
await TestExactActionSetOfferedAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ internal class CSharpUpgradeProjectCodeFixProvider : AbstractUpgradeProjectCodeF
private const string CS8302 = nameof(CS8302); // error CS8302: Feature is not available in C# 7.1. Please use language version X or greater.
private const string CS8306 = nameof(CS8306); // error CS8306: ... Please use language version 7.1 or greater to access a un-named element by its inferred name.
private const string CS8314 = nameof(CS8314); // error CS9003: An expression of type '{0}' cannot be handled by a pattern of type '{1}' in C# {2}. Please use language version {3} or greater.
private const string CS8320 = nameof(CS8320); // error CS8320: Feature is not available in C# 7.2. Please use language version X or greater.

public override ImmutableArray<string> FixableDiagnosticIds { get; } =
ImmutableArray.Create(CS8022, CS8023, CS8024, CS8025, CS8026, CS8059, CS8107, CS8302, CS8306, CS8314);
ImmutableArray.Create(CS8022, CS8023, CS8024, CS8025, CS8026, CS8059, CS8107, CS8302, CS8306, CS8314, CS8320);

public override string UpgradeThisProjectResource => CSharpFeaturesResources.Upgrade_this_project_to_csharp_language_version_0;
public override string UpgradeAllProjectsResource => CSharpFeaturesResources.Upgrade_all_csharp_projects_to_language_version_0;
Expand Down