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

Hide replace/original functionality behind a feature flag. #11157

Merged
merged 1 commit into from
May 9, 2016
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
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/CSharpParseOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ internal bool IsFeatureEnabled(MessageID feature)
case MessageID.IDS_FeatureRefLocalsReturns:
case MessageID.IDS_FeaturePatternMatching:
case MessageID.IDS_FeatureTuples:
case MessageID.IDS_FeatureReplace:
// in "demo" mode enable proposed new C# 7 language features.
if (PreprocessorSymbols.Contains("__DEMO__"))
{
Expand Down
9 changes: 9 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.Designer.cs

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

3 changes: 3 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@
<data name="IDS_FeaturePartialMethod" xml:space="preserve">
<value>partial method</value>
</data>
<data name="IDS_FeatureReplace" xml:space="preserve">
<value>replaced members</value>
</data>
<data name="IDS_SK_METHOD" xml:space="preserve">
<value>method</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/MessageID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ internal enum MessageID

IDS_FeatureRefLocalsReturns = MessageBase + 12710,
IDS_FeatureTuples = MessageBase + 12711,
IDS_FeatureReplace = MessageBase + 12712,
}

// Message IDs may refer to strings that need to be localized.
Expand Down Expand Up @@ -174,6 +175,8 @@ internal static string RequiredFeature(this MessageID feature)
return "patterns";
case MessageID.IDS_FeatureTuples:
return "tuples";
case MessageID.IDS_FeatureReplace:
return "replace";
default:
return null;
}
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,7 @@ private void ParseModifiers(SyntaxListBuilder tokens)
if (ShouldCurrentContextualKeywordBeTreatedAsModifier())
{
modTok = ConvertToKeyword(this.EatToken());
modTok = CheckFeatureAvailability(modTok, MessageID.IDS_FeatureReplace);
break;
}
return;
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Test/Symbol/Symbols/ReplaceOriginalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Symbols
{
public class ReplaceOriginalTests : CSharpTestBase
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider marking tests with the feature attribute.

Copy link
Member

Choose a reason for hiding this comment

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

@AlekseyTs agree. This is now a pre-req before merging to future so let's do this now.

{
private static CSharpCompilation CreateCompilationWithMscorlib(string text)
{
return CreateCompilationWithMscorlib(text, parseOptions: TestOptions.Regular.WithReplaceFeature());
}

private static CSharpCompilation CreateCompilationWithMscorlib(string text, CSharpCompilationOptions options)
{
return CreateCompilationWithMscorlib(text, options: options, parseOptions: TestOptions.Regular.WithReplaceFeature());
}
Copy link
Member

Choose a reason for hiding this comment

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

Consider using options = null and removing the other overload.

Copy link
Member Author

Choose a reason for hiding this comment

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

done in a new change. Thanks


[WorkItem(11123, "https://github.com/dotnet/roslyn/issues/11123")]
[Fact]
public void Members()
Expand Down
21 changes: 17 additions & 4 deletions src/Compilers/CSharp/Test/Syntax/Parsing/ReplaceParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Xunit;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using System;
Copy link
Member

Choose a reason for hiding this comment

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

Sort usings

Copy link
Member Author

Choose a reason for hiding this comment

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

done in a new change


namespace Microsoft.CodeAnalysis.CSharp.UnitTests
{
public class ReplaceParsingTests
public class ReplaceParsingTests: CSharpTestBase
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider marking tests with the feature attribute.

{
[Fact]
public void ReplaceClass()
{
var root = SyntaxFactory.ParseCompilationUnit("abstract replace override class C { }");
var root = SyntaxFactory.ParseCompilationUnit("abstract replace override class C { }", options: TestOptions.Regular.WithReplaceFeature());
root.Errors().Verify();
var type = (TypeDeclarationSyntax)root.Members[0];
Assert.Equal(
Expand All @@ -23,7 +25,7 @@ public void ReplaceClass()
[Fact]
public void ReplaceMethod()
{
var root = SyntaxFactory.ParseCompilationUnit("class C { virtual replace protected void M() { } }");
var root = SyntaxFactory.ParseCompilationUnit("class C { virtual replace protected void M() { } }", options: TestOptions.Regular.WithReplaceFeature());
root.Errors().Verify();
var type = (TypeDeclarationSyntax)root.Members[0];
Assert.Equal(
Expand All @@ -35,6 +37,17 @@ public void ReplaceMethod()
DeclarationModifiers.Virtual | DeclarationModifiers.Protected | DeclarationModifiers.Replace);
}

[Fact]
public void ReplaceMethodNoFeature()
{
var source = "class C { virtual replace protected void M() { } }";
CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll).VerifyDiagnostics(
// (1,19): error CS8058: Feature 'replaced members' is experimental and unsupported; use '/features:replace' to enable.
// class C { virtual replace protected void M() { } }
Diagnostic(ErrorCode.ERR_FeatureIsExperimental, "replace").WithArguments("replaced members", "replace").WithLocation(1, 19)
);
}

[Fact]
public void OriginalExpression()
{
Expand Down Expand Up @@ -72,7 +85,7 @@ public void OriginalInReplace()

private void OriginalInMember(string text, bool inReplace)
{
var tree = SyntaxFactory.ParseSyntaxTree(text);
var tree = SyntaxFactory.ParseSyntaxTree(text, options: TestOptions.Regular.WithReplaceFeature());
var root = tree.GetCompilationUnitRoot();
root.Errors().Verify();
var token = root.DescendantTokens().Where(t => t.Text == "original").Single();
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/Test/Utilities/CSharp.Desktop/TestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,10 @@ public static CSharpParseOptions WithPatternsFeature(this CSharpParseOptions opt
{
return options.WithFeature("patterns", "true");
}

public static CSharpParseOptions WithReplaceFeature(this CSharpParseOptions options)
{
return options.WithFeature("replace", "true");
}
}
}
5 changes: 5 additions & 0 deletions src/Compilers/Test/Utilities/CSharp/TestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,10 @@ public static CSharpParseOptions WithTuplesFeature(this CSharpParseOptions optio
{
return options.WithFeature("tuples", "true");
}

public static CSharpParseOptions WithReplaceFeature(this CSharpParseOptions options)
{
return options.WithFeature("replace", "true");
}
}
}