diff --git a/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md b/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md index 4f99b63cec964..c54414b5cd266 100644 --- a/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md +++ b/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md @@ -96,11 +96,6 @@ Possible workarounds are: 1. Rename the type parameter or parameter to avoid shadowing the name from outer scope. 1. Use a string literal instead of the `nameof` operator. -1. Downgrade the `` element to 9.0 or earlier. - -Note: The break will also apply to C# 10 and earlier when .NET 7 ships, but is -currently scoped down to users of LangVer=preview. -Tracked by https://github.com/dotnet/roslyn/issues/60640 ## Cannot return an out parameter by reference diff --git a/src/Compilers/CSharp/Portable/Binder/LocalBinderFactory.cs b/src/Compilers/CSharp/Portable/Binder/LocalBinderFactory.cs index fa18c09ed906d..e65bc3cf59486 100644 --- a/src/Compilers/CSharp/Portable/Binder/LocalBinderFactory.cs +++ b/src/Compilers/CSharp/Portable/Binder/LocalBinderFactory.cs @@ -208,9 +208,7 @@ public override void VisitInvocationExpression(InvocationExpressionSyntax node) WithTypeParametersBinder? withTypeParametersBinder; Binder? withParametersBinder; - // The LangVer check will be removed before shipping .NET 7. - // Tracked by https://github.com/dotnet/roslyn/issues/60640 - if (((_enclosing.Flags & BinderFlags.InContextualAttributeBinder) != 0) && _enclosing.Compilation.IsFeatureEnabled(MessageID.IDS_FeatureExtendedNameofScope)) + if ((_enclosing.Flags & BinderFlags.InContextualAttributeBinder) != 0) { var attributeTarget = getAttributeTarget(_enclosing); withTypeParametersBinder = getExtraWithTypeParametersBinder(_enclosing, attributeTarget); diff --git a/src/Compilers/CSharp/Portable/Errors/MessageID.cs b/src/Compilers/CSharp/Portable/Errors/MessageID.cs index 0cb52e6c2fea5..d45d3000eca6a 100644 --- a/src/Compilers/CSharp/Portable/Errors/MessageID.cs +++ b/src/Compilers/CSharp/Portable/Errors/MessageID.cs @@ -252,12 +252,11 @@ internal enum MessageID IDS_FeatureUtf8StringLiterals = MessageBase + 12822, IDS_FeatureUnsignedRightShift = MessageBase + 12823, - IDS_FeatureExtendedNameofScope = MessageBase + 12824, - IDS_FeatureRelaxedShiftOperator = MessageBase + 12825, - IDS_FeatureRequiredMembers = MessageBase + 12826, - IDS_FeatureRefFields = MessageBase + 12827, - IDS_FeatureFileTypes = MessageBase + 12828, + IDS_FeatureRelaxedShiftOperator = MessageBase + 12824, + IDS_FeatureRequiredMembers = MessageBase + 12825, + IDS_FeatureRefFields = MessageBase + 12826, + IDS_FeatureFileTypes = MessageBase + 12827, } // Message IDs may refer to strings that need to be localized. @@ -379,7 +378,6 @@ internal static LanguageVersion RequiredVersion(this MessageID feature) case MessageID.IDS_FeatureCheckedUserDefinedOperators: // semantic check for declarations, parsing check for doc comments case MessageID.IDS_FeatureUtf8StringLiterals: // semantic check case MessageID.IDS_FeatureUnsignedRightShift: // semantic check for declarations and consumption, parsing check for doc comments - case MessageID.IDS_FeatureExtendedNameofScope: // semantic check case MessageID.IDS_FeatureRelaxedShiftOperator: // semantic check case MessageID.IDS_FeatureRefFields: // semantic check case MessageID.IDS_FeatureFileTypes: // semantic check diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs index d134238caf131..235d24c05402c 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs @@ -7119,8 +7119,8 @@ async static void B4() { } Diagnostic(ErrorCode.WRN_LowerCaseTypeName, "await").WithArguments("await").WithLocation(23, 30)); } - [Fact, WorkItem(59775, "https://github.com/dotnet/roslyn/issues/59775")] - public void TypeParameterScope_InMethodAttributeNameOf() + [Theory, CombinatorialData, WorkItem(59775, "https://github.com/dotnet/roslyn/issues/59775")] + public void TypeParameterScope_InMethodAttributeNameOf(bool useCSharp10) { var source = @" class C @@ -7142,28 +7142,15 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (8,20): error CS0103: The name 'TParameter' does not exist in the current context - // [My(nameof(TParameter))] // 1 - Diagnostic(ErrorCode.ERR_NameNotInContext, "TParameter").WithArguments("TParameter").WithLocation(8, 20), - // (12,16): error CS0103: The name 'TParameter' does not exist in the current context - // [My(nameof(TParameter))] // 2 - Diagnostic(ErrorCode.ERR_NameNotInContext, "TParameter").WithArguments("TParameter").WithLocation(12, 16) - ); - - VerifyTParameter(comp, 0, null); - VerifyTParameter(comp, 1, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyTParameter(comp, 0, "void local()"); VerifyTParameter(comp, 1, "void C.M2()"); } - [Fact, WorkItem(59775, "https://github.com/dotnet/roslyn/issues/59775")] - public void TypeParameterScope_InMethodAttributeNameOfNameOf() + [Theory, CombinatorialData, WorkItem(59775, "https://github.com/dotnet/roslyn/issues/59775")] + public void TypeParameterScope_InMethodAttributeNameOfNameOf(bool useCSharp10) { var source = @" class C @@ -7185,20 +7172,7 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (8,27): error CS0103: The name 'TParameter' does not exist in the current context - // [My(nameof(nameof(TParameter)))] // 1 - Diagnostic(ErrorCode.ERR_NameNotInContext, "TParameter").WithArguments("TParameter").WithLocation(8, 27), - // (12,23): error CS0103: The name 'TParameter' does not exist in the current context - // [My(nameof(nameof(TParameter)))] // 2 - Diagnostic(ErrorCode.ERR_NameNotInContext, "TParameter").WithArguments("TParameter").WithLocation(12, 23) - ); - - VerifyTParameter(comp, 0, null); - VerifyTParameter(comp, 1, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics( // (8,20): error CS8081: Expression does not have a name. // [My(nameof(nameof(TParameter)))] // 1 @@ -7212,8 +7186,8 @@ public MyAttribute(string name1) { } VerifyTParameter(comp, 1, "void C.M2()"); } - [Fact, WorkItem(59775, "https://github.com/dotnet/roslyn/issues/59775")] - public void TypeParameterScope_InMethodAttributeNameOf_TopLevel() + [Theory, CombinatorialData, WorkItem(59775, "https://github.com/dotnet/roslyn/issues/59775")] + public void TypeParameterScope_InMethodAttributeNameOf_TopLevel(bool useCSharp10) { var source = @" local(); @@ -7226,23 +7200,14 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (4,12): error CS0103: The name 'TParameter' does not exist in the current context - // [My(nameof(TParameter))] // 1 - Diagnostic(ErrorCode.ERR_NameNotInContext, "TParameter").WithArguments("TParameter").WithLocation(4, 12) - ); - - VerifyTParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyTParameter(comp, 0, "void local()"); } - [Fact] - public void TypeParameterScope_InMethodAttributeNameOf_SpeculatingWithNewAttribute() + [Theory, CombinatorialData] + public void TypeParameterScope_InMethodAttributeNameOf_SpeculatingWithNewAttribute(bool useCSharp10) { var source = @" class C @@ -7264,35 +7229,20 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - // C# 10 - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); + var parseOptions = useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext; + var comp = CreateCompilation(source, parseOptions: parseOptions); comp.VerifyDiagnostics(); - var tree = comp.SyntaxTrees.Single(); - var parentModel = comp.GetSemanticModel(tree); // Note: offset by one to the left to get away from return type var localFuncPosition = tree.GetText().ToString().IndexOf("void local()", StringComparison.Ordinal) - 1; var methodPosition = tree.GetText().ToString().IndexOf("void M2()", StringComparison.Ordinal) - 1; + var parentModel = comp.GetSemanticModel(tree); - var attr = parseAttributeSyntax("[My(nameof(TParameter))]", TestOptions.Regular10); - VerifyTParameterSpeculation(parentModel, localFuncPosition, attr, found: false); - VerifyTParameterSpeculation(parentModel, methodPosition, attr, found: false); - - attr = parseAttributeSyntax("[My(TParameter)]", TestOptions.Regular10); - VerifyTParameterSpeculation(parentModel, localFuncPosition, attr, found: false); - VerifyTParameterSpeculation(parentModel, methodPosition, attr, found: false); - - // C# 11 - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); - comp.VerifyDiagnostics(); - tree = comp.SyntaxTrees.Single(); - parentModel = comp.GetSemanticModel(tree); - - attr = parseAttributeSyntax("[My(nameof(TParameter))]", TestOptions.RegularNext); + var attr = parseAttributeSyntax("[My(nameof(TParameter))]", parseOptions); VerifyTParameterSpeculation(parentModel, localFuncPosition, attr, found: false); VerifyTParameterSpeculation(parentModel, methodPosition, attr, found: false); - attr = parseAttributeSyntax("[My(TParameter)]", TestOptions.RegularNext); + attr = parseAttributeSyntax("[My(TParameter)]", parseOptions); VerifyTParameterSpeculation(parentModel, localFuncPosition, attr, found: false); VerifyTParameterSpeculation(parentModel, methodPosition, attr, found: false); @@ -7327,8 +7277,8 @@ static IdentifierNameSyntax getTParameter(CSharpSyntaxNode node) } } - [Fact] - public void TypeParameterScope_InMethodAttributeNameOf_SpeculatingWithinAttribute() + [Theory, CombinatorialData] + public void TypeParameterScope_InMethodAttributeNameOf_SpeculatingWithinAttribute(bool useCSharp10) { var source = @" class C @@ -7352,8 +7302,9 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - // C# 10 - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); + + var parseOptions = useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext; + var comp = CreateCompilation(source, parseOptions: parseOptions); comp.VerifyDiagnostics( // (8,13): error CS0103: The name 'a' does not exist in the current context // [My(a)] @@ -7373,51 +7324,17 @@ public MyAttribute(string name1) { } var parentModel = comp.GetSemanticModel(tree); var aPosition = getIdentifierPosition("a"); - var newNameOf = parseNameof("nameof(TParameter)", parseOptions: TestOptions.Regular10); + var newNameOf = parseNameof("nameof(TParameter)", parseOptions: parseOptions); Assert.Equal("System.String", parentModel.GetSpeculativeTypeInfo(aPosition, newNameOf, SpeculativeBindingOption.BindAsExpression).Type.ToTestDisplayString()); var bPosition = getIdentifierPosition("b"); - var newNameOfArgument = parseIdentifier("TParameter", parseOptions: TestOptions.Regular10); - Assert.True(parentModel.GetSpeculativeTypeInfo(bPosition, newNameOfArgument, SpeculativeBindingOption.BindAsExpression).Type.IsErrorType()); + var newNameOfArgument = parseIdentifier("TParameter", parseOptions: parseOptions); + Assert.Equal("TParameter", parentModel.GetSpeculativeTypeInfo(bPosition, newNameOfArgument, SpeculativeBindingOption.BindAsExpression).Type.ToTestDisplayString()); var cPosition = getIdentifierPosition("c"); Assert.Equal("System.String", parentModel.GetSpeculativeTypeInfo(cPosition, newNameOf, SpeculativeBindingOption.BindAsExpression).Type.ToTestDisplayString()); var dPosition = getIdentifierPosition("d"); - Assert.True(parentModel.GetSpeculativeTypeInfo(dPosition, newNameOfArgument, SpeculativeBindingOption.BindAsExpression).Type.IsErrorType()); - - // C# 11 - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); - comp.VerifyDiagnostics( - // (8,13): error CS0103: The name 'a' does not exist in the current context - // [My(a)] - Diagnostic(ErrorCode.ERR_NameNotInContext, "a").WithArguments("a").WithLocation(8, 13), - // (9,20): error CS0103: The name 'b' does not exist in the current context - // [My(nameof(b))] - Diagnostic(ErrorCode.ERR_NameNotInContext, "b").WithArguments("b").WithLocation(9, 20), - // (13,9): error CS0103: The name 'c' does not exist in the current context - // [My(c)] - Diagnostic(ErrorCode.ERR_NameNotInContext, "c").WithArguments("c").WithLocation(13, 9), - // (14,16): error CS0103: The name 'd' does not exist in the current context - // [My(nameof(d))] - Diagnostic(ErrorCode.ERR_NameNotInContext, "d").WithArguments("d").WithLocation(14, 16) - ); - - tree = comp.SyntaxTrees.Single(); - parentModel = comp.GetSemanticModel(tree); - - aPosition = getIdentifierPosition("a"); - newNameOf = parseNameof("nameof(TParameter)", parseOptions: TestOptions.RegularNext); - Assert.Equal("System.String", parentModel.GetSpeculativeTypeInfo(aPosition, newNameOf, SpeculativeBindingOption.BindAsExpression).Type.ToTestDisplayString()); - - bPosition = getIdentifierPosition("b"); - newNameOfArgument = parseIdentifier("TParameter", parseOptions: TestOptions.RegularNext); - Assert.Equal("TParameter", parentModel.GetSpeculativeTypeInfo(bPosition, newNameOfArgument, SpeculativeBindingOption.BindAsExpression).Type.ToTestDisplayString()); - - cPosition = getIdentifierPosition("c"); - Assert.Equal("System.String", parentModel.GetSpeculativeTypeInfo(cPosition, newNameOf, SpeculativeBindingOption.BindAsExpression).Type.ToTestDisplayString()); - - dPosition = getIdentifierPosition("d"); Assert.Equal("TParameter", parentModel.GetSpeculativeTypeInfo(dPosition, newNameOfArgument, SpeculativeBindingOption.BindAsExpression).Type.ToTestDisplayString()); return; @@ -7508,8 +7425,8 @@ static AttributeSyntax parseAttributeSyntax(string source, CSharpParseOptions pa => SyntaxFactory.ParseCompilationUnit($@"class X {{ {source} void M() {{ }} }}", options: parseOptions).DescendantNodes().OfType().Single(); } - [Fact] - public void TypeParameterScope_InMethodAttributeNameOf_SpeculatingWithReplacementAttributeInsideExisting() + [Theory, CombinatorialData] + public void TypeParameterScope_InMethodAttributeNameOf_SpeculatingWithReplacementAttributeInsideExisting(bool useCSharp10) { var source = @" class C @@ -7531,8 +7448,8 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - // C# 10 - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); + var parseOptions = useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext; + var comp = CreateCompilation(source, parseOptions: parseOptions); comp.VerifyDiagnostics( // (8,13): error CS0103: The name 'positionA' does not exist in the current context // [My(positionA)] @@ -7547,33 +7464,11 @@ public MyAttribute(string name1) { } var localFuncPosition = tree.GetText().ToString().IndexOf("positionA", StringComparison.Ordinal); var methodPosition = tree.GetText().ToString().IndexOf("positionB", StringComparison.Ordinal); - var attr = parseAttributeSyntax("[My(nameof(TParameter))]", TestOptions.Regular10); - VerifyTParameterSpeculation(parentModel, localFuncPosition, attr, found: false); - VerifyTParameterSpeculation(parentModel, methodPosition, attr, found: false); - - attr = parseAttributeSyntax("[My(TParameter)]", TestOptions.Regular10); - VerifyTParameterSpeculation(parentModel, localFuncPosition, attr, found: false); - VerifyTParameterSpeculation(parentModel, methodPosition, attr, found: false); - - // C# 11 - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); - comp.VerifyDiagnostics( - // (8,13): error CS0103: The name 'positionA' does not exist in the current context - // [My(positionA)] - Diagnostic(ErrorCode.ERR_NameNotInContext, "positionA").WithArguments("positionA").WithLocation(8, 13), - // (12,9): error CS0103: The name 'positionB' does not exist in the current context - // [My(positionB)] - Diagnostic(ErrorCode.ERR_NameNotInContext, "positionB").WithArguments("positionB").WithLocation(12, 9) - ); - - tree = comp.SyntaxTrees.Single(); - parentModel = comp.GetSemanticModel(tree); - - attr = parseAttributeSyntax("[My(nameof(TParameter))]", TestOptions.Regular10); + var attr = parseAttributeSyntax("[My(nameof(TParameter))]", parseOptions); VerifyTParameterSpeculation(parentModel, localFuncPosition, attr); VerifyTParameterSpeculation(parentModel, methodPosition, attr); - attr = parseAttributeSyntax("[My(TParameter)]", TestOptions.Regular10); + attr = parseAttributeSyntax("[My(TParameter)]", parseOptions); VerifyTParameterSpeculation(parentModel, localFuncPosition, attr, found: false); VerifyTParameterSpeculation(parentModel, methodPosition, attr, found: false); @@ -7583,9 +7478,9 @@ static AttributeSyntax parseAttributeSyntax(string source, CSharpParseOptions pa => SyntaxFactory.ParseCompilationUnit($@"class X {{ {source} void M() {{ }} }}", options: parseOptions).DescendantNodes().OfType().Single(); } - [Fact, WorkItem(59775, "https://github.com/dotnet/roslyn/issues/59775")] + [Theory, CombinatorialData, WorkItem(59775, "https://github.com/dotnet/roslyn/issues/59775")] [WorkItem(60194, "https://github.com/dotnet/roslyn/issues/60194")] - public void TypeParameterScope_InMethodAttributeNameOf_CompatBreak() + public void TypeParameterScope_InMethodAttributeNameOf_CompatBreak(bool useCSharp10) { var source = @" class C @@ -7612,16 +7507,8 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - // The break will also apply to C# 10 and earlier when .NET 7 ships, - // but is currently scoped down to users of LangVer=preview. - // Tracked by https://github.com/dotnet/roslyn/issues/60640 - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics(); - VerifyTParameter(comp, 0, "C", symbolKind: SymbolKind.NamedType, lookupFinds: "C.TParameter"); - VerifyTParameter(comp, 1, "C", symbolKind: SymbolKind.NamedType, lookupFinds: "C.TParameter"); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics( // (13,20): error CS0704: Cannot do non-virtual member lookup in 'TParameter' because it is a type parameter // [My(nameof(TParameter.Constant))] // 1 @@ -8650,8 +8537,8 @@ public interface I VerifyTParameter(comp, 0, "R"); } - [Fact] - public void ParameterScope_InMethodAttributeNameOf() + [Theory, CombinatorialData] + public void ParameterScope_InMethodAttributeNameOf(bool useCSharp10) { var source = @" class C @@ -8673,20 +8560,7 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (8,20): error CS0103: The name 'parameter' does not exist in the current context - // [My(nameof(parameter))] // 1 - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(8, 20), - // (12,16): error CS0103: The name 'parameter' does not exist in the current context - // [My(nameof(parameter))] // 2 - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(12, 16) - ); - - VerifyParameter(comp, 0, null); - VerifyParameter(comp, 1, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "void local(System.Int32 parameter)"); @@ -8800,8 +8674,8 @@ public MyAttribute(string name1) { } Assert.False(model.LookupSymbols(nameofExpression.ArgumentList.CloseParenToken.SpanStart).ToTestDisplayStrings().Contains("parameter")); } - [Fact] - public void ParameterScope_InMethodAttributeNameOf_ConflictingNames() + [Theory, CombinatorialData] + public void ParameterScope_InMethodAttributeNameOf_ConflictingNames(bool useCSharp10) { var source = @" class C @@ -8823,26 +8697,7 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (8,20): error CS0103: The name 'parameter' does not exist in the current context - // [My(nameof(parameter))] - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(8, 20), - // (9,36): error CS0412: 'parameter': a parameter, local variable, or local function cannot have the same name as a method type parameter - // void local<@parameter>(int parameter) => throw null; - Diagnostic(ErrorCode.ERR_LocalSameNameAsTypeParam, "parameter").WithArguments("parameter").WithLocation(9, 36), - // (12,16): error CS0103: The name 'parameter' does not exist in the current context - // [My(nameof(parameter))] - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(12, 16), - // (13,29): error CS0412: 'parameter': a parameter, local variable, or local function cannot have the same name as a method type parameter - // void M2<@parameter>(int parameter) => throw null; - Diagnostic(ErrorCode.ERR_LocalSameNameAsTypeParam, "parameter").WithArguments("parameter").WithLocation(13, 29) - ); - - VerifyParameter(comp, 0, null); - VerifyParameter(comp, 1, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics( // (9,36): error CS0412: 'parameter': a parameter, local variable, or local function cannot have the same name as a method type parameter // void local<@parameter>(int parameter) => throw null; @@ -8856,8 +8711,8 @@ public MyAttribute(string name1) { } VerifyParameter(comp, 1, "void C.M2(System.Int32 parameter)"); } - [Fact] - public void ParameterScope_InMethodAttributeNameOf_CompatBreak() + [Theory, CombinatorialData] + public void ParameterScope_InMethodAttributeNameOf_CompatBreak(bool useCSharp10) { var source = @" class C @@ -8884,13 +8739,7 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - // The break will also apply to C# 10 and earlier when .NET 7 ships, - // but is currently scoped down to users of LangVer=preview. - // Tracked by https://github.com/dotnet/roslyn/issues/60640 - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics(); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics( // (13,30): error CS1061: 'int' does not contain a definition for 'Constant' and no accessible extension method 'Constant' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?) // [My(nameof(parameter.Constant))] // 1 @@ -8901,8 +8750,8 @@ public MyAttribute(string name1) { } ); } - [Fact] - public void ParameterScope_InMethodAttributeNameOf_WithReturnTarget() + [Theory, CombinatorialData] + public void ParameterScope_InMethodAttributeNameOf_WithReturnTarget(bool useCSharp10) { var source = @" class C @@ -8924,28 +8773,15 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (8,28): error CS0103: The name 'parameter' does not exist in the current context - // [return: My(nameof(parameter))] // 1 - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(8, 28), - // (12,24): error CS0103: The name 'parameter' does not exist in the current context - // [return: My(nameof(parameter))] // 2 - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(12, 24) - ); - - VerifyParameter(comp, 0, null); - VerifyParameter(comp, 1, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "void local(System.Int32 parameter)"); VerifyParameter(comp, 1, "void C.M2(System.Int32 parameter)"); } - [Fact] - public void ParameterScope_InMethodAttributeNameOf_SpeculatingWithReplacementAttributeInsideExisting() + [Theory, CombinatorialData] + public void ParameterScope_InMethodAttributeNameOf_SpeculatingWithReplacementAttributeInsideExisting(bool useCSharp10) { var source = @" class C @@ -8967,8 +8803,8 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - // C# 10 - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); + var parseOptions = useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext; + var comp = CreateCompilation(source, parseOptions: parseOptions); comp.VerifyDiagnostics( // (8,13): error CS0103: The name 'positionA' does not exist in the current context // [My(positionA)] @@ -8983,33 +8819,11 @@ public MyAttribute(string name1) { } var localFuncPosition = tree.GetText().ToString().IndexOf("positionA", StringComparison.Ordinal); var methodPosition = tree.GetText().ToString().IndexOf("positionB", StringComparison.Ordinal); - var attr = parseAttributeSyntax("[My(nameof(parameter))]", TestOptions.Regular10); - VerifyParameterSpeculation(parentModel, localFuncPosition, attr, found: false); - VerifyParameterSpeculation(parentModel, methodPosition, attr, found: false); - - attr = parseAttributeSyntax("[My(parameter)]", TestOptions.Regular10); - VerifyParameterSpeculation(parentModel, localFuncPosition, attr, found: false); - VerifyParameterSpeculation(parentModel, methodPosition, attr, found: false); - - // C# 11 - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); - comp.VerifyDiagnostics( - // (8,13): error CS0103: The name 'positionA' does not exist in the current context - // [My(positionA)] - Diagnostic(ErrorCode.ERR_NameNotInContext, "positionA").WithArguments("positionA").WithLocation(8, 13), - // (12,9): error CS0103: The name 'positionB' does not exist in the current context - // [My(positionB)] - Diagnostic(ErrorCode.ERR_NameNotInContext, "positionB").WithArguments("positionB").WithLocation(12, 9) - ); - - tree = comp.SyntaxTrees.Single(); - parentModel = comp.GetSemanticModel(tree); - - attr = parseAttributeSyntax("[My(nameof(parameter))]", TestOptions.Regular10); + var attr = parseAttributeSyntax("[My(nameof(parameter))]", parseOptions); VerifyParameterSpeculation(parentModel, localFuncPosition, attr); VerifyParameterSpeculation(parentModel, methodPosition, attr); - attr = parseAttributeSyntax("[My(parameter)]", TestOptions.Regular10); + attr = parseAttributeSyntax("[My(parameter)]", parseOptions); VerifyParameterSpeculation(parentModel, localFuncPosition, attr, found: false); VerifyParameterSpeculation(parentModel, methodPosition, attr, found: false); @@ -9043,8 +8857,8 @@ static IdentifierNameSyntax getParameter(CSharpSyntaxNode node) } } - [Fact] - public void ParameterScope_InIndexerAttributeNameOf() + [Theory, CombinatorialData] + public void ParameterScope_InIndexerAttributeNameOf(bool useCSharp10) { var source = @" class C @@ -9058,23 +8872,14 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (4,16): error CS0103: The name 'parameter' does not exist in the current context - // [My(nameof(parameter))] - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(4, 16) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "System.Int32 C.this[System.Int32 parameter] { get; }"); } - [Fact] - public void ParameterScope_InIndexerAttributeNameOf_SetterOnly() + [Theory, CombinatorialData] + public void ParameterScope_InIndexerAttributeNameOf_SetterOnly(bool useCSharp10) { var source = @" class C @@ -9088,23 +8893,14 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (4,16): error CS0103: The name 'parameter' does not exist in the current context - // [My(nameof(parameter))] - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(4, 16) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "System.Int32 C.this[System.Int32 parameter] { set; }"); } - [Fact] - public void ParameterScope_InIndexerGetterAttributeNameOf() + [Theory, CombinatorialData] + public void ParameterScope_InIndexerGetterAttributeNameOf(bool useCSharp10) { var source = @" class C @@ -9121,23 +8917,14 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (6,20): error CS0103: The name 'parameter' does not exist in the current context - // [My(nameof(parameter))] - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(6, 20) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "System.Int32 C.this[System.Int32 parameter].get"); } - [Fact] - public void ParameterScope_InIndexerSetterAttributeNameOf() + [Theory, CombinatorialData] + public void ParameterScope_InIndexerSetterAttributeNameOf(bool useCSharp10) { var source = @" class C @@ -9154,23 +8941,14 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (6,20): error CS0103: The name 'parameter' does not exist in the current context - // [My(nameof(parameter))] - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(6, 20) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "void C.this[System.Int32 parameter].set"); } - [Fact] - public void ParameterScope_InIndexerInitSetterAttributeNameOf() + [Theory, CombinatorialData] + public void ParameterScope_InIndexerInitSetterAttributeNameOf(bool useCSharp10) { var source = @" class C @@ -9187,23 +8965,14 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (6,20): error CS0103: The name 'parameter' does not exist in the current context - // [My(nameof(parameter))] - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(6, 20) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "void modreq(System.Runtime.CompilerServices.IsExternalInit) C.this[System.Int32 parameter].init"); } - [Fact] - public void ParameterScope_InMethodAttributeNameOf_Lambda() + [Theory, CombinatorialData] + public void ParameterScope_InMethodAttributeNameOf_Lambda(bool useCSharp10) { var source = @" class C @@ -9219,16 +8988,7 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (6,28): error CS0103: The name 'parameter' does not exist in the current context - // var x = [My(nameof(parameter))] int (int parameter) => 0; - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(6, 28) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "lambda expression"); @@ -9271,8 +9031,8 @@ public MyAttribute(string name1) { } ); } - [Fact] - public void ParameterScope_InMethodAttributeNameOf_Delegate() + [Theory, CombinatorialData] + public void ParameterScope_InMethodAttributeNameOf_Delegate(bool useCSharp10) { var source = @" [My(nameof(parameter))] delegate int MyDelegate(int parameter); @@ -9282,23 +9042,14 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (2,12): error CS0103: The name 'parameter' does not exist in the current context - // [My(nameof(parameter))] delegate int MyDelegate(int parameter); - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(2, 12) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "System.Int32 MyDelegate.Invoke(System.Int32 parameter)"); } - [Fact] - public void ParameterScope_InMethodAttributeNameOf_Delegate_ConflictingName() + [Theory, CombinatorialData] + public void ParameterScope_InMethodAttributeNameOf_Delegate_ConflictingName(bool useCSharp10) { var source = @" [My(nameof(TParameter))] delegate int MyDelegate(int TParameter); @@ -9308,19 +9059,14 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics(); - - VerifyTParameter(comp, 0, "MyDelegate"); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "System.Int32 MyDelegate.Invoke(System.Int32 TParameter)", parameterName: "TParameter"); } - [Fact] - public void ParameterScope_InMethodAttributeNameOf_Constructor() + [Theory, CombinatorialData] + public void ParameterScope_InMethodAttributeNameOf_Constructor(bool useCSharp10) { var source = @" class C @@ -9333,16 +9079,7 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (4,16): error CS0103: The name 'parameter' does not exist in the current context - // [My(nameof(parameter))] C(int parameter) { } - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(4, 16) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "C..ctor(System.Int32 parameter)"); @@ -9490,8 +9227,8 @@ public MyAttribute(string name1) { } VerifyParameter(comp, 1, null); } - [Fact] - public void ParameterScope_InParameterAttributeNameOf() + [Theory, CombinatorialData] + public void ParameterScope_InParameterAttributeNameOf(bool useCSharp10) { var source = @" class C @@ -9511,28 +9248,15 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (8,31): error CS0103: The name 'parameter' does not exist in the current context - // void local([My(nameof(parameter))] int parameter) => throw null; - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(8, 31), - // (11,24): error CS0103: The name 'parameter' does not exist in the current context - // void M2([My(nameof(parameter))] int parameter) => throw null; - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(11, 24) - ); - - VerifyParameter(comp, 0, null); - VerifyParameter(comp, 1, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "void local(System.Int32 parameter)"); VerifyParameter(comp, 1, "void C.M2(System.Int32 parameter)"); } - [Fact] - public void ParameterScope_InParameterAttributeNameOf_ConflictingNames() + [Theory, CombinatorialData] + public void ParameterScope_InParameterAttributeNameOf_ConflictingNames(bool useCSharp10) { var source = @" class C @@ -9552,20 +9276,7 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (8,61): error CS0412: 'TParameter': a parameter, local variable, or local function cannot have the same name as a method type parameter - // void local([My(nameof(TParameter))] int TParameter) => throw null; - Diagnostic(ErrorCode.ERR_LocalSameNameAsTypeParam, "TParameter").WithArguments("TParameter").WithLocation(8, 61), - // (11,54): error CS0412: 'TParameter': a parameter, local variable, or local function cannot have the same name as a method type parameter - // void M2([My(nameof(TParameter))] int TParameter) => throw null; - Diagnostic(ErrorCode.ERR_LocalSameNameAsTypeParam, "TParameter").WithArguments("TParameter").WithLocation(11, 54) - ); - - VerifyTParameter(comp, 0, "void local(System.Int32 TParameter)"); - VerifyTParameter(comp, 1, "void C.M2(System.Int32 TParameter)"); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics( // (8,61): error CS0412: 'TParameter': a parameter, local variable, or local function cannot have the same name as a method type parameter // void local([My(nameof(TParameter))] int TParameter) => throw null; @@ -9579,8 +9290,8 @@ public MyAttribute(string name1) { } VerifyParameter(comp, 1, "void C.M2(System.Int32 TParameter)", parameterName: "TParameter"); } - [Fact] - public void ParameterScope_InParameterAttributeNameOf_SpeculatingWithReplacementAttributeInsideExisting() + [Theory, CombinatorialData] + public void ParameterScope_InParameterAttributeNameOf_SpeculatingWithReplacementAttributeInsideExisting(bool useCSharp10) { var source = @" class C @@ -9600,8 +9311,8 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - // C# 10 - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); + var parseOptions = useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext; + var comp = CreateCompilation(source, parseOptions: parseOptions); comp.VerifyDiagnostics( // (8,24): error CS0103: The name 'positionA' does not exist in the current context // void local([My(positionA)] int parameter) { } @@ -9617,28 +9328,6 @@ public MyAttribute(string name1) { } var methodPosition = tree.GetText().ToString().IndexOf("positionB", StringComparison.Ordinal); var attr = parseAttributeSyntax("[My(nameof(parameter))]", TestOptions.Regular10); - VerifyParameterSpeculation(parentModel, localFuncPosition, attr, found: false); - VerifyParameterSpeculation(parentModel, methodPosition, attr, found: false); - - attr = parseAttributeSyntax("[My(parameter)]", TestOptions.Regular10); - VerifyParameterSpeculation(parentModel, localFuncPosition, attr, found: false); - VerifyParameterSpeculation(parentModel, methodPosition, attr, found: false); - - // C# 11 - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); - comp.VerifyDiagnostics( - // (8,24): error CS0103: The name 'positionA' does not exist in the current context - // void local([My(positionA)] int parameter) { } - Diagnostic(ErrorCode.ERR_NameNotInContext, "positionA").WithArguments("positionA").WithLocation(8, 24), - // (11,17): error CS0103: The name 'positionB' does not exist in the current context - // void M2([My(positionB)] int parameter) { } - Diagnostic(ErrorCode.ERR_NameNotInContext, "positionB").WithArguments("positionB").WithLocation(11, 17) - ); - - tree = comp.SyntaxTrees.Single(); - parentModel = comp.GetSemanticModel(tree); - - attr = parseAttributeSyntax("[My(nameof(parameter))]", TestOptions.Regular10); VerifyParameterSpeculation(parentModel, localFuncPosition, attr); VerifyParameterSpeculation(parentModel, methodPosition, attr); @@ -9652,8 +9341,8 @@ static AttributeSyntax parseAttributeSyntax(string source, CSharpParseOptions pa => SyntaxFactory.ParseCompilationUnit($@"class X {{ {source} void M() {{ }} }}", options: parseOptions).DescendantNodes().OfType().Single(); } - [Fact] - public void ParameterScope_InParameterAttributeNameOf_Indexer() + [Theory, CombinatorialData] + public void ParameterScope_InParameterAttributeNameOf_Indexer(bool useCSharp10) { var source = @" class C @@ -9666,23 +9355,14 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (4,25): error CS0103: The name 'parameter' does not exist in the current context - // int this[[My(nameof(parameter))] int parameter] => throw null; - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(4, 25) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "System.Int32 C.this[System.Int32 parameter] { get; }"); } - [Fact] - public void ParameterScope_InParameterAttributeNameOf_Indexer_SetterOnly() + [Theory, CombinatorialData] + public void ParameterScope_InParameterAttributeNameOf_Indexer_SetterOnly(bool useCSharp10) { var source = @" class C @@ -9695,16 +9375,7 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (4,25): error CS0103: The name 'parameter' does not exist in the current context - // int this[[My(nameof(parameter))] int parameter] => throw null; - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(4, 25) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "System.Int32 C.this[System.Int32 parameter] { set; }"); @@ -9782,8 +9453,8 @@ public MyAttribute(string name) { } Assert.Null(model.GetSymbolInfo(node).Symbol); } - [Fact] - public void ParameterScope_InParameterAttributeNameOf_Constructor() + [Theory, CombinatorialData] + public void ParameterScope_InParameterAttributeNameOf_Constructor(bool useCSharp10) { var source = @" class C @@ -9796,23 +9467,14 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (4,18): error CS0103: The name 'parameter' does not exist in the current context - // C([My(nameof(parameter))] int parameter) => throw null; - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(4, 18) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "C..ctor(System.Int32 parameter)"); } - [Fact] - public void ParameterScope_InParameterAttributeNameOf_Delegate() + [Theory, CombinatorialData] + public void ParameterScope_InParameterAttributeNameOf_Delegate(bool useCSharp10) { var source = @" delegate void MyDelegate([My(nameof(parameter))] int parameter); @@ -9822,23 +9484,14 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (2,37): error CS0103: The name 'parameter' does not exist in the current context - // delegate void MyDelegate([My(nameof(parameter))] int parameter); - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(2, 37) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "void MyDelegate.Invoke(System.Int32 parameter)"); } - [Fact] - public void ParameterScope_InParameterAttributeNameOf_ConversionOperator() + [Theory, CombinatorialData] + public void ParameterScope_InParameterAttributeNameOf_ConversionOperator(bool useCSharp10) { var source = @" class C @@ -9851,23 +9504,14 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (4,50): error CS0103: The name 'parameter' does not exist in the current context - // public static implicit operator C([My(nameof(parameter))] int parameter) => throw null; - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(4, 50) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "C C.op_Implicit(System.Int32 parameter)"); } - [Fact] - public void ParameterScope_InParameterAttributeNameOf_Operator() + [Theory, CombinatorialData] + public void ParameterScope_InParameterAttributeNameOf_Operator(bool useCSharp10) { var source = @" class C @@ -9880,23 +9524,14 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (4,43): error CS0103: The name 'parameter' does not exist in the current context - // public static C operator +([My(nameof(parameter))] int parameter, C other) => throw null; - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(4, 43) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "C C.op_Addition(System.Int32 parameter, C other)"); } - [Fact] - public void ParameterScope_InParameterAttributeNameOf_Lambda() + [Theory, CombinatorialData] + public void ParameterScope_InParameterAttributeNameOf_Lambda(bool useCSharp10) { var source = @" class C @@ -9912,16 +9547,7 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (6,29): error CS0103: The name 'parameter' does not exist in the current context - // var x = ([My(nameof(parameter))] int parameter) => 0; - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(6, 29) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "lambda expression"); @@ -9954,8 +9580,8 @@ public MyAttribute(string name1) { } VerifyParameter(comp, 0, "lambda expression"); } - [Fact] - public void ParameterScope_InTypeParameterAttributeNameOf() + [Theory, CombinatorialData] + public void ParameterScope_InTypeParameterAttributeNameOf(bool useCSharp10) { var source = @" class C @@ -9975,28 +9601,15 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (8,31): error CS0103: The name 'parameter' does not exist in the current context - // void local<[My(nameof(parameter))] T>(int parameter) { } - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(8, 31), - // (11,24): error CS0103: The name 'parameter' does not exist in the current context - // void M2<[My(nameof(parameter))] T>(int parameter) { } - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(11, 24) - ); - - VerifyParameter(comp, 0, null); - VerifyParameter(comp, 1, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "void local(System.Int32 parameter)"); VerifyParameter(comp, 1, "void C.M2(System.Int32 parameter)"); } - [Fact] - public void ParameterScope_InTypeParameterAttributeNameOf_SpeculatingWithReplacementAttributeInsideExisting() + [Theory, CombinatorialData] + public void ParameterScope_InTypeParameterAttributeNameOf_SpeculatingWithReplacementAttributeInsideExisting(bool useCSharp10) { var source = @" class C @@ -10016,8 +9629,8 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - // C# 10 - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); + var parseOptions = useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext; + var comp = CreateCompilation(source, parseOptions: parseOptions); comp.VerifyDiagnostics( // (8,24): error CS0103: The name 'positionA' does not exist in the current context // void local([My(positionA)] int parameter) { } @@ -10033,28 +9646,6 @@ public MyAttribute(string name1) { } var methodPosition = tree.GetText().ToString().IndexOf("positionB", StringComparison.Ordinal); var attr = parseAttributeSyntax("[My(nameof(parameter))]", TestOptions.Regular10); - VerifyParameterSpeculation(parentModel, localFuncPosition, attr, found: false); - VerifyParameterSpeculation(parentModel, methodPosition, attr, found: false); - - attr = parseAttributeSyntax("[My(parameter)]", TestOptions.Regular10); - VerifyParameterSpeculation(parentModel, localFuncPosition, attr, found: false); - VerifyParameterSpeculation(parentModel, methodPosition, attr, found: false); - - // C# 11 - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); - comp.VerifyDiagnostics( - // (8,24): error CS0103: The name 'positionA' does not exist in the current context - // void local([My(positionA)] int parameter) { } - Diagnostic(ErrorCode.ERR_NameNotInContext, "positionA").WithArguments("positionA").WithLocation(8, 24), - // (11,17): error CS0103: The name 'positionB' does not exist in the current context - // void M2([My(positionB)] int parameter) { } - Diagnostic(ErrorCode.ERR_NameNotInContext, "positionB").WithArguments("positionB").WithLocation(11, 17) - ); - - tree = comp.SyntaxTrees.Single(); - parentModel = comp.GetSemanticModel(tree); - - attr = parseAttributeSyntax("[My(nameof(parameter))]", TestOptions.Regular10); VerifyParameterSpeculation(parentModel, localFuncPosition, attr); VerifyParameterSpeculation(parentModel, methodPosition, attr); @@ -10068,8 +9659,8 @@ static AttributeSyntax parseAttributeSyntax(string source, CSharpParseOptions pa => SyntaxFactory.ParseCompilationUnit($@"class X {{ {source} void M() {{ }} }}", options: parseOptions).DescendantNodes().OfType().Single(); } - [Fact] - public void ParameterScope_InTypeParameterAttributeNameOf_Delegate() + [Theory, CombinatorialData] + public void ParameterScope_InTypeParameterAttributeNameOf_Delegate(bool useCSharp10) { var source = @" delegate int MyDelegate<[My(nameof(parameter))] T>(int parameter); @@ -10079,16 +9670,7 @@ public class MyAttribute : System.Attribute public MyAttribute(string name1) { } } "; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular10); - comp.VerifyDiagnostics( - // (2,36): error CS0103: The name 'parameter' does not exist in the current context - // delegate int MyDelegate<[My(nameof(parameter))] T>(int parameter); - Diagnostic(ErrorCode.ERR_NameNotInContext, "parameter").WithArguments("parameter").WithLocation(2, 36) - ); - - VerifyParameter(comp, 0, null); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularNext); + var comp = CreateCompilation(source, parseOptions: useCSharp10 ? TestOptions.Regular10 : TestOptions.RegularNext); comp.VerifyDiagnostics(); VerifyParameter(comp, 0, "System.Int32 MyDelegate.Invoke(System.Int32 parameter)"); diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests.cs index 7934a8dd8be98..41baa0adc2592 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests.cs @@ -12108,7 +12108,7 @@ void M(int parameter) { } "; await VerifyItemExistsAsync(MakeMarkup(source), "parameter"); - await VerifyItemIsAbsentAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); + await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); } [Fact] @@ -12154,7 +12154,7 @@ void local(int parameter) { } // Tracked by https://github.com/dotnet/roslyn/issues/60801 await VerifyItemExistsAsync(MakeMarkup(source), "parameter", skipSpeculation: true); - await VerifyItemIsAbsentAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); + await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: "10"), "parameter", skipSpeculation: true); } [Fact] @@ -12173,7 +12173,7 @@ void local([Some(nameof(p$$))] int parameter) { } // Tracked by https://github.com/dotnet/roslyn/issues/60801 await VerifyItemExistsAsync(MakeMarkup(source), "parameter", skipSpeculation: true); - await VerifyItemIsAbsentAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); + await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: "10"), "parameter", skipSpeculation: true); } [Fact] @@ -12192,7 +12192,7 @@ void M() // Tracked by https://github.com/dotnet/roslyn/issues/60801 await VerifyItemExistsAsync(MakeMarkup(source), "parameter", skipSpeculation: true); - await VerifyItemIsAbsentAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); + await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: "10"), "parameter", skipSpeculation: true); } [Fact] @@ -12211,7 +12211,7 @@ void M() // Tracked by https://github.com/dotnet/roslyn/issues/60801 await VerifyItemExistsAsync(MakeMarkup(source), "parameter", skipSpeculation: true); - await VerifyItemIsAbsentAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); + await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: "10"), "parameter", skipSpeculation: true); } [Fact] @@ -12223,7 +12223,7 @@ public async Task ParameterAvailableInDelegateAttributeNameof() "; await VerifyItemExistsAsync(MakeMarkup(source), "parameter"); - await VerifyItemIsAbsentAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); + await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); } [Fact] @@ -12236,7 +12236,7 @@ public async Task ParameterAvailableInDelegateParameterAttributeNameof() // Tracked by https://github.com/dotnet/roslyn/issues/60801 await VerifyItemExistsAsync(MakeMarkup(source), "parameter", skipSpeculation: true); - await VerifyItemIsAbsentAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); + await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: "10"), "parameter", skipSpeculation: true); } private static string MakeMarkup(string source, string languageVersion = "Preview")