Skip to content

Commit 0ee3dc1

Browse files
authored
Extensions: resolve some follow-up comments on signature conflicts and betterness (#78442)
1 parent f64a80d commit 0ee3dc1

File tree

1 file changed

+3
-39
lines changed

1 file changed

+3
-39
lines changed

src/Compilers/CSharp/Test/Emit3/Semantics/ExtensionTests.cs

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23945,7 +23945,6 @@ public void M13() {}
2394523945
""";
2394623946
var comp = CreateCompilation(src);
2394723947

23948-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : Despite the fact that we do not complain about M6, should we report an error for M2 (the only difference is receiver ref-ness)?
2394923948
comp.VerifyDiagnostics(
2395023949
// (10,21): error CS0111: Type 'Extensions' already defines a member called 'M1' with the same parameter types
2395123950
// public void M1() {}
@@ -24150,22 +24149,15 @@ public static void M12(in int x) {}
2415024149
// (46,28): error CS0111: Type 'Extensions' already defines a member called 'M5' with the same parameter types
2415124150
// static public void M5() {}
2415224151
Diagnostic(ErrorCode.ERR_MemberAlreadyExists, "M5").WithArguments("M5", "Extensions").WithLocation(46, 28),
24153-
24154-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : It feels unfortunate that we generate conflicting signatures, the methods extend different types (refer to M6 and M7 cases)
24155-
2415624152
// (56,28): error CS0111: Type 'Extensions' already defines a member called 'M6' with the same parameter types
2415724153
// static public void M6() {}
2415824154
Diagnostic(ErrorCode.ERR_MemberAlreadyExists, "M6").WithArguments("M6", "Extensions").WithLocation(56, 28),
2415924155
// (66,28): error CS0111: Type 'Extensions' already defines a member called 'M7' with the same parameter types
2416024156
// static public long M7() => 0;
24161-
Diagnostic(ErrorCode.ERR_MemberAlreadyExists, "M7").WithArguments("M7", "Extensions").WithLocation(66, 28), // Tracked by https://github.com/dotnet/roslyn/issues/76130 : Signatures in metadata are different in this case (return type is different), consider if we want to enable this specific case
24162-
24157+
Diagnostic(ErrorCode.ERR_MemberAlreadyExists, "M7").WithArguments("M7", "Extensions").WithLocation(66, 28),
2416324158
// (76,28): error CS0111: Type 'Extensions' already defines a member called 'M8' with the same parameter types
2416424159
// public static void M8() {}
2416524160
Diagnostic(ErrorCode.ERR_MemberAlreadyExists, "M8").WithArguments("M8", "Extensions").WithLocation(76, 28),
24166-
24167-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : Are we comfortable with these four conflicts?
24168-
2416924161
// (86,28): error CS0111: Type 'Extensions' already defines a member called 'M9' with the same parameter types
2417024162
// public static void M9(int x) {}
2417124163
Diagnostic(ErrorCode.ERR_MemberAlreadyExists, "M9").WithArguments("M9", "Extensions").WithLocation(86, 28),
@@ -24517,7 +24509,6 @@ public static void M13(object receiver2) {}
2451724509
""";
2451824510
var comp = CreateCompilation(src);
2451924511

24520-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : Should we report an error for M2 (the only difference is receiver ref-ness)?
2452124512
comp.VerifyDiagnostics(
2452224513
// (5,21): error CS0111: Type 'Extensions' already defines a member called 'M1' with the same parameter types
2452324514
// public void M1() {}
@@ -24646,7 +24637,6 @@ public void M13() {}
2464624637
""";
2464724638
var comp = CreateCompilation(src);
2464824639

24649-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : Should we report an error for M2 (the only difference is receiver ref-ness)?
2465024640
comp.VerifyDiagnostics(
2465124641
// (7,21): error CS0111: Type 'Extensions' already defines a member called 'M1' with the same parameter types
2465224642
// public void M1() {}
@@ -24765,15 +24755,9 @@ public static void M10(in int x) {}
2476524755
// (26,28): error CS0663: 'Extensions' cannot define an overloaded method that differs only on parameter modifiers 'ref' and 'in'
2476624756
// static public void M4(ref int x) {}
2476724757
Diagnostic(ErrorCode.ERR_OverloadRefKind, "M4").WithArguments("Extensions", "method", "ref", "in").WithLocation(26, 28),
24768-
24769-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : It feels unfortunate that we generate conflicting signatures
24770-
2477124758
// (34,27): error CS0111: Type 'Extensions' already defines a member called 'M7' with the same parameter types
2477224759
// static public int M7() => 0;
2477324760
Diagnostic(ErrorCode.ERR_MemberAlreadyExists, "M7").WithArguments("M7", "Extensions").WithLocation(34, 27),
24774-
24775-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : Are we comfortable with these two conflicts?
24776-
2477724761
// (44,28): error CS0111: Type 'Extensions' already defines a member called 'M9' with the same parameter types
2477824762
// public static void M9(int x) {}
2477924763
Diagnostic(ErrorCode.ERR_MemberAlreadyExists, "M9").WithArguments("M9", "Extensions").WithLocation(44, 28),
@@ -24889,15 +24873,9 @@ public static void M10(ref int receiver) {}
2488924873
// (28,28): error CS0663: 'Extensions' cannot define an overloaded method that differs only on parameter modifiers 'ref' and 'in'
2489024874
// static public void M4(ref int x) {}
2489124875
Diagnostic(ErrorCode.ERR_OverloadRefKind, "M4").WithArguments("Extensions", "method", "ref", "in").WithLocation(28, 28),
24892-
24893-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : It feels unfortunate that we generate conflicting signatures
24894-
2489524876
// (35,27): error CS0111: Type 'Extensions' already defines a member called 'M7' with the same parameter types
2489624877
// static public int M7() => 0;
2489724878
Diagnostic(ErrorCode.ERR_MemberAlreadyExists, "M7").WithArguments("M7", "Extensions").WithLocation(35, 27),
24898-
24899-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : Are we comfortable with these two conflicts?
24900-
2490124879
// (40,28): error CS0111: Type 'Extensions' already defines a member called 'M9' with the same parameter types
2490224880
// public static void M9(int x) {}
2490324881
Diagnostic(ErrorCode.ERR_MemberAlreadyExists, "M9").WithArguments("M9", "Extensions").WithLocation(40, 28),
@@ -25045,12 +25023,9 @@ public static int P2 {set{}}
2504525023
var comp = CreateCompilation(src);
2504625024

2504725025
comp.VerifyDiagnostics(
25048-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : Are we comfortable reporting an error like this?
25049-
2505025026
// (8,23): error CS0082: Type 'Extensions' already reserves a member called 'get_P1' with the same parameter types
2505125027
// public static int P1 {set{}}
2505225028
Diagnostic(ErrorCode.ERR_MemberReserved, "P1").WithArguments("get_P1", "Extensions").WithLocation(8, 23),
25053-
2505425029
// (11,23): error CS0082: Type 'Extensions' already reserves a member called 'get_P2' with the same parameter types
2505525030
// public static int P2 {set{}}
2505625031
Diagnostic(ErrorCode.ERR_MemberReserved, "P2").WithArguments("get_P2", "Extensions").WithLocation(11, 23)
@@ -25077,12 +25052,9 @@ static class Extensions
2507725052
var comp = CreateCompilation(src);
2507825053

2507925054
comp.VerifyDiagnostics(
25080-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : Are we comfortable reporting an error like this?
25081-
2508225055
// (8,23): error CS0082: Type 'Extensions' already reserves a member called 'set_P1' with the same parameter types
2508325056
// public static int P1 => 4;
2508425057
Diagnostic(ErrorCode.ERR_MemberReserved, "P1").WithArguments("set_P1", "Extensions").WithLocation(8, 23),
25085-
2508625058
// (11,23): error CS0082: Type 'Extensions' already reserves a member called 'set_P2' with the same parameter types
2508725059
// public static int P2 => 4;
2508825060
Diagnostic(ErrorCode.ERR_MemberReserved, "P2").WithArguments("set_P2", "Extensions").WithLocation(11, 23)
@@ -26801,7 +26773,6 @@ interface I<out T> { }
2680126773
class C1 { }
2680226774
class C2 : C1 { }
2680326775
""";
26804-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : confirm whether we want this betterness behavior (for methods and/or properties)
2680526776
var comp = CreateCompilation(src);
2680626777
comp.VerifyEmitDiagnostics();
2680726778

@@ -26923,7 +26894,6 @@ static class E2
2692326894
}
2692426895
}
2692526896
""";
26926-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : confirm whether we want this betterness behavior (for methods and/or properties)
2692726897
var comp = CreateCompilation(src);
2692826898
comp.VerifyEmitDiagnostics();
2692926899

@@ -26954,7 +26924,6 @@ static class E2
2695426924
}
2695526925
}
2695626926
""";
26957-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : confirm whether we want this betterness behavior for methods
2695826927
var comp = CreateCompilation(src);
2695926928
comp.VerifyEmitDiagnostics(
2696026929
// (1,5): error CS0121: The call is ambiguous between the following methods or properties: 'E1.extension(int).M<T>(T)' and 'E2.extension<T>(T).M(int)'
@@ -26986,7 +26955,6 @@ static class E2
2698626955
}
2698726956
}
2698826957
""";
26989-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : confirm whether we want this betterness behavior for methods when the receiver is a type
2699026958
var comp = CreateCompilation(src);
2699126959
CompileAndVerify(comp, expectedOutput: "ran ran2").VerifyDiagnostics();
2699226960

@@ -28075,7 +28043,6 @@ static class E2
2807528043
}
2807628044
}
2807728045
""";
28078-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : confirm what betterness behavior we want for static properties
2807928046
var comp = CreateCompilation(source);
2808028047
CompileAndVerify(comp, expectedOutput: "42").VerifyDiagnostics();
2808128048

@@ -28107,14 +28074,13 @@ static class E
2810728074
}
2810828075
}
2810928076
""";
28110-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : confirm what betterness behavior we want for properties
2811128077
var comp = CreateCompilation(src);
2811228078
CompileAndVerify(comp, expectedOutput: "42").VerifyDiagnostics();
2811328079

2811428080
var tree = comp.SyntaxTrees.Single();
2811528081
var model = comp.GetSemanticModel(tree);
2811628082
var memberAccess = GetSyntax<MemberAccessExpressionSyntax>(tree, "i.P");
28117-
Assert.Equal("System.Int32 E.<>E__0.P { get; }", model.GetSymbolInfo(memberAccess).Symbol.ToTestDisplayString());
28083+
Assert.Equal("E.extension(I<string>).P", model.GetSymbolInfo(memberAccess).Symbol.ToDisplayString());
2811828084
Assert.Equal([], model.GetSymbolInfo(memberAccess).CandidateSymbols.ToTestDisplayStrings());
2811928085
}
2812028086

@@ -28139,14 +28105,13 @@ static class E
2813928105
}
2814028106
}
2814128107
""";
28142-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : confirm what betterness behavior we want for properties
2814328108
var comp = CreateCompilation(src);
2814428109
CompileAndVerify(comp, expectedOutput: "42").VerifyDiagnostics();
2814528110

2814628111
var tree = comp.SyntaxTrees.Single();
2814728112
var model = comp.GetSemanticModel(tree);
2814828113
var memberAccess = GetSyntax<MemberAccessExpressionSyntax>(tree, "i.P");
28149-
Assert.Equal("System.Int32 E.<>E__1.P { get; }", model.GetSymbolInfo(memberAccess).Symbol.ToTestDisplayString());
28114+
Assert.Equal("E.extension(I<string>).P", model.GetSymbolInfo(memberAccess).Symbol.ToDisplayString());
2815028115
Assert.Equal([], model.GetSymbolInfo(memberAccess).CandidateSymbols.ToTestDisplayStrings());
2815128116
}
2815228117

@@ -28171,7 +28136,6 @@ static class E2
2817128136
}
2817228137
}
2817328138
""";
28174-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : confirm what betterness behavior we want for properties
2817528139
var comp = CreateCompilation(src);
2817628140
CompileAndVerify(comp, expectedOutput: "42").VerifyDiagnostics();
2817728141

0 commit comments

Comments
 (0)