diff --git a/src/Analyzers/Core/Analyzers/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs b/src/Analyzers/Core/Analyzers/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs index 25a6556ddb684..f0e8e33a86227 100644 --- a/src/Analyzers/Core/Analyzers/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs +++ b/src/Analyzers/Core/Analyzers/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs @@ -696,7 +696,8 @@ private bool IsCandidateSymbol(ISymbol memberSymbol) } private bool IsEntryPoint(IMethodSymbol methodSymbol) - => (methodSymbol.Name == WellKnownMemberNames.EntryPointMethodName || methodSymbol.Name == "$Main") && + => (methodSymbol.Name == WellKnownMemberNames.EntryPointMethodName || methodSymbol.Name == "
$") && // https://github.com/dotnet/roslyn/issues/45110 Switch to using WellKnownMemberNames.TopLevelStatementsEntryPointMethodName + // once src\CodeStyle\Core\Analyzers\Microsoft.CodeAnalysis.CodeStyle.csproj is able to use the latest version of the type. methodSymbol.IsStatic && (methodSymbol.ReturnsVoid || methodSymbol.ReturnType.SpecialType == SpecialType.System_Int32 || diff --git a/src/Compilers/CSharp/Portable/Declarations/DeclarationTreeBuilder.cs b/src/Compilers/CSharp/Portable/Declarations/DeclarationTreeBuilder.cs index 2c086a194e96d..6e7181f4b4742 100644 --- a/src/Compilers/CSharp/Portable/Declarations/DeclarationTreeBuilder.cs +++ b/src/Compilers/CSharp/Portable/Declarations/DeclarationTreeBuilder.cs @@ -131,7 +131,7 @@ private static SingleNamespaceOrTypeDeclaration CreateSimpleProgram(GlobalStatem { return new SingleTypeDeclaration( kind: DeclarationKind.SimpleProgram, - name: SimpleProgramNamedTypeSymbol.UnspeakableName, + name: WellKnownMemberNames.TopLevelStatementsEntryPointTypeName, arity: 0, modifiers: DeclarationModifiers.Internal | DeclarationModifiers.Partial | DeclarationModifiers.Static, declFlags: (hasAwaitExpressions ? SingleTypeDeclaration.TypeDeclarationFlags.HasAwaitExpressions : SingleTypeDeclaration.TypeDeclarationFlags.None) | diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SimpleProgramNamedTypeSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SimpleProgramNamedTypeSymbol.cs index 08f30a2c087e4..75f396bfffbde 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SimpleProgramNamedTypeSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SimpleProgramNamedTypeSymbol.cs @@ -23,14 +23,12 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols /// internal sealed class SimpleProgramNamedTypeSymbol : SourceMemberContainerTypeSymbol { - internal const string UnspeakableName = "$Program"; - internal SimpleProgramNamedTypeSymbol(NamespaceSymbol globalNamespace, MergedTypeDeclaration declaration, DiagnosticBag diagnostics) : base(globalNamespace, declaration, diagnostics) { Debug.Assert(globalNamespace.IsGlobalNamespace); Debug.Assert(declaration.Kind == DeclarationKind.SimpleProgram); - Debug.Assert(declaration.Name == UnspeakableName); + Debug.Assert(declaration.Name == WellKnownMemberNames.TopLevelStatementsEntryPointTypeName); state.NotePartComplete(CompletionPart.EnumUnderlyingType); // No work to do for this. } @@ -42,7 +40,7 @@ internal SimpleProgramNamedTypeSymbol(NamespaceSymbol globalNamespace, MergedTyp private static SimpleProgramNamedTypeSymbol? GetSimpleProgramNamedTypeSymbol(CSharpCompilation compilation) { - return compilation.SourceModule.GlobalNamespace.GetTypeMembers(UnspeakableName).OfType().SingleOrDefault(); + return compilation.SourceModule.GlobalNamespace.GetTypeMembers(WellKnownMemberNames.TopLevelStatementsEntryPointTypeName).OfType().SingleOrDefault(); } internal static SynthesizedSimpleProgramEntryPointSymbol? GetSimpleProgramEntryPoint(CSharpCompilation compilation, CompilationUnitSyntax compilationUnit, bool fallbackToMainEntryPoint) diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs index b12e4839f50e8..ef17789df2390 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs @@ -18,8 +18,6 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols { internal sealed class SynthesizedSimpleProgramEntryPointSymbol : SourceMemberMethodSymbol { - internal const string UnspeakableName = "$Main"; - /// /// The corresponding . /// @@ -73,7 +71,7 @@ public override string Name { get { - return UnspeakableName; + return WellKnownMemberNames.TopLevelStatementsEntryPointMethodName; } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/AnonymousFunctionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/AnonymousFunctionTests.cs index 2ef9fe06b06d4..44a1b22585a66 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/AnonymousFunctionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/AnonymousFunctionTests.cs @@ -1241,7 +1241,7 @@ void local(Func fn) { Console.WriteLine(fn(0)); }"; - VerifyInPreview(source, expectedOutput: "1", metadataName: "$Program.<>c.<$Main>b__0_0", expectedIL: @" + VerifyInPreview(source, expectedOutput: "1", metadataName: WellKnownMemberNames.TopLevelStatementsEntryPointTypeName + ".<>c.<" + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName + ">b__0_0", expectedIL: @" { // Code size 5 (0x5) .maxstack 2 diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs index ef034d279d19e..d71df226fa18f 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs @@ -2173,7 +2173,7 @@ void M() { } var cMembers = comp.GlobalNamespace.GetMember("C").GetMembers(); AssertEx.SetEqual(new[] { - "C C.<>Clone()", + "C C." + WellKnownMemberNames.CloneMethodName + "()", "System.Type C.EqualityContract.get", "System.Type C.EqualityContract { get; }", "C..ctor(System.Int32 i)", diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs index 98bb862cebc41..287385c0e4b96 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs @@ -336,7 +336,7 @@ public void set_X() { } var actualMembers = comp.GetMember("C").GetMembers().ToTestDisplayStrings(); var expectedMembers = new[] { - "C C.<>Clone()", + "C C." + WellKnownMemberNames.CloneMethodName + "()", "System.Type C.EqualityContract.get", "System.Type C.EqualityContract { get; }", "C..ctor(System.Int32 X, System.Int32 Y)", @@ -720,7 +720,7 @@ public static void Main() Left: ILocalReferenceOperation: c (OperationKind.LocalReference, Type: C) (Syntax: 'c') Right: - IInvocationOperation (virtual C C.<>Clone()) (OperationKind.Invocation, Type: C, IsImplicit) (Syntax: 'c with { }') + IInvocationOperation (virtual C C." + WellKnownMemberNames.CloneMethodName + @"()) (OperationKind.Invocation, Type: C, IsImplicit) (Syntax: 'c with { }') Instance Receiver: ILocalReferenceOperation: c (OperationKind.LocalReference, Type: C) (Syntax: 'c') Arguments(0) @@ -895,7 +895,7 @@ .maxstack 3 IL_0006: dup IL_0007: callvirt ""int C.X.get"" IL_000c: call ""void System.Console.WriteLine(int)"" - IL_0011: callvirt ""C C.<>Clone()"" + IL_0011: callvirt ""C C." + WellKnownMemberNames.CloneMethodName + @"()"" IL_0016: dup IL_0017: ldc.i4.5 IL_0018: callvirt ""void C.X.init"" @@ -933,7 +933,7 @@ .maxstack 3 IL_0002: newobj ""C..ctor(int, int)"" IL_0007: dup IL_0008: call ""void System.Console.WriteLine(object)"" - IL_000d: callvirt ""C C.<>Clone()"" + IL_000d: callvirt ""C C." + WellKnownMemberNames.CloneMethodName + @"()"" IL_0012: dup IL_0013: ldc.i4.5 IL_0014: callvirt ""void C.X.init"" @@ -973,13 +973,13 @@ .maxstack 3 IL_0002: newobj ""C..ctor(int, int)"" IL_0007: dup IL_0008: call ""void System.Console.WriteLine(object)"" - IL_000d: callvirt ""C C.<>Clone()"" + IL_000d: callvirt ""C C." + WellKnownMemberNames.CloneMethodName + @"()"" IL_0012: dup IL_0013: ldc.i4.5 IL_0014: callvirt ""void C.X.init"" IL_0019: dup IL_001a: call ""void System.Console.WriteLine(object)"" - IL_001f: callvirt ""C C.<>Clone()"" + IL_001f: callvirt ""C C." + WellKnownMemberNames.CloneMethodName + @"()"" IL_0024: dup IL_0025: ldc.i4.2 IL_0026: callvirt ""void C.Y.init"" @@ -1293,7 +1293,7 @@ implements class [mscorlib]System.IEquatable`1 .field private initonly int32 'k__BackingField' .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .method public hidebysig specialname newslot virtual instance class Base '<>Clone' () cil managed + .method public hidebysig specialname newslot virtual instance class Base '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { IL_0000: ldarg.0 IL_0001: newobj instance void Base::.ctor(class Base) @@ -1471,7 +1471,7 @@ protected C(C other) var verifier = CompileAndVerify(source, expectedOutput: @"1 11"); - verifier.VerifyIL("C.<>Clone", @" + verifier.VerifyIL("C." + WellKnownMemberNames.CloneMethodName, @" { // Code size 7 (0x7) .maxstack 1 @@ -1480,6 +1480,9 @@ .maxstack 1 IL_0006: ret } "); + + var clone = verifier.Compilation.GetMember("C." + WellKnownMemberNames.CloneMethodName); + Assert.Equal("$", clone.Name); } [Fact] @@ -1510,7 +1513,7 @@ protected C(C other) var verifier = CompileAndVerify(source, expectedOutput: @"1 11"); - verifier.VerifyIL("C.<>Clone", @" + verifier.VerifyIL("C." + WellKnownMemberNames.CloneMethodName, @" { // Code size 7 (0x7) .maxstack 1 @@ -1550,7 +1553,7 @@ protected C(C other) var verifier = CompileAndVerify(source, expectedOutput: @"1 11"); - verifier.VerifyIL("C.<>Clone", @" + verifier.VerifyIL("C." + WellKnownMemberNames.CloneMethodName, @" { // Code size 7 (0x7) .maxstack 1 @@ -1584,7 +1587,7 @@ protected C(ref C other) : this(-1) var verifier = CompileAndVerify(source, expectedOutput: @"1 11"); - verifier.VerifyIL("C.<>Clone", @" + verifier.VerifyIL("C." + WellKnownMemberNames.CloneMethodName, @" { // Code size 7 (0x7) .maxstack 1 @@ -1618,7 +1621,7 @@ protected C(in C other) : this(-1) var verifier = CompileAndVerify(source, expectedOutput: @"1 11"); - verifier.VerifyIL("C.<>Clone", @" + verifier.VerifyIL("C." + WellKnownMemberNames.CloneMethodName, @" { // Code size 7 (0x7) .maxstack 1 @@ -1653,7 +1656,7 @@ protected C(out C other) : this(-1) var verifier = CompileAndVerify(source, expectedOutput: @"1 11"); - verifier.VerifyIL("C.<>Clone", @" + verifier.VerifyIL("C." + WellKnownMemberNames.CloneMethodName, @" { // Code size 7 (0x7) .maxstack 1 @@ -1895,7 +1898,7 @@ .maxstack 3 IL_0001: ldc.i4.1 IL_0002: ldc.i4.2 IL_0003: newobj ""C..ctor(int, int, int)"" - IL_0008: callvirt ""C C.<>Clone()"" + IL_0008: callvirt ""C C." + WellKnownMemberNames.CloneMethodName + @"()"" IL_000d: dup IL_000e: ldstr ""Y"" IL_0013: call ""int C.W(string)"" @@ -1918,7 +1921,7 @@ .maxstack 3 IWithOperation (OperationKind.With, Type: C) (Syntax: 'c with { Y ... = W(""X"") }') Operand: ILocalReferenceOperation: c (OperationKind.LocalReference, Type: C) (Syntax: 'c') - CloneMethod: C C.<>Clone() + CloneMethod: C C." + WellKnownMemberNames.CloneMethodName + @"() Initializer: IObjectOrCollectionInitializerOperation (OperationKind.ObjectOrCollectionInitializer, Type: C) (Syntax: '{ Y = W(""Y"" ... = W(""X"") }') Initializers(2): @@ -1998,7 +2001,7 @@ .maxstack 3 ILocalReferenceOperation: c (OperationKind.LocalReference, Type: C) (Syntax: 'c') IFlowCaptureOperation: 1 (OperationKind.FlowCapture, Type: null, IsImplicit) (Syntax: 'c with { Y ... = W(""X"") }') Value: - IInvocationOperation (virtual C C.<>Clone()) (OperationKind.Invocation, Type: C, IsImplicit) (Syntax: 'c with { Y ... = W(""X"") }') + IInvocationOperation (virtual C C." + WellKnownMemberNames.CloneMethodName + @"()) (OperationKind.Invocation, Type: C, IsImplicit) (Syntax: 'c with { Y ... = W(""X"") }') Instance Receiver: ILocalReferenceOperation: c (OperationKind.LocalReference, Type: C) (Syntax: 'c') Arguments(0) @@ -2068,7 +2071,7 @@ .maxstack 3 IL_0000: ldc.i4.0 IL_0001: conv.i8 IL_0002: newobj ""C..ctor(long)"" - IL_0007: callvirt ""C C.<>Clone()"" + IL_0007: callvirt ""C C." + WellKnownMemberNames.CloneMethodName + @"()"" IL_000c: dup IL_000d: ldc.i4.s 11 IL_000f: conv.i8 @@ -2120,7 +2123,7 @@ .locals init (S V_0) //s IL_0007: ldloca.s V_0 IL_0009: ldc.i4.s 11 IL_000b: call ""S..ctor(int)"" - IL_0010: callvirt ""C C.<>Clone()"" + IL_0010: callvirt ""C C." + WellKnownMemberNames.CloneMethodName + @"()"" IL_0015: dup IL_0016: ldloc.0 IL_0017: call ""long S.op_Implicit(S)"" @@ -2253,7 +2256,7 @@ .locals init (S V_0) //s IL_0005: ldloca.s V_0 IL_0007: ldc.i4.s 11 IL_0009: call ""S..ctor(int)"" - IL_000e: callvirt ""C C.<>Clone()"" + IL_000e: callvirt ""C C." + WellKnownMemberNames.CloneMethodName + @"()"" IL_0013: dup IL_0014: ldloc.0 IL_0015: call ""int S.op_Implicit(S)"" @@ -2439,7 +2442,7 @@ public static void Main() IWithOperation (OperationKind.With, Type: C) (Syntax: 'c with { X = 2 }') Operand: ILocalReferenceOperation: c (OperationKind.LocalReference, Type: C) (Syntax: 'c') - CloneMethod: C C.<>Clone() + CloneMethod: C C." + WellKnownMemberNames.CloneMethodName + @"() Initializer: IObjectOrCollectionInitializerOperation (OperationKind.ObjectOrCollectionInitializer, Type: C) (Syntax: '{ X = 2 }') Initializers(1): @@ -2493,7 +2496,7 @@ public static void Main() ILocalReferenceOperation: c (OperationKind.LocalReference, Type: C) (Syntax: 'c') IFlowCaptureOperation: 1 (OperationKind.FlowCapture, Type: null, IsImplicit) (Syntax: 'c with { X = 2 }') Value: - IInvocationOperation (virtual C C.<>Clone()) (OperationKind.Invocation, Type: C, IsImplicit) (Syntax: 'c with { X = 2 }') + IInvocationOperation (virtual C C." + WellKnownMemberNames.CloneMethodName + @"()) (OperationKind.Invocation, Type: C, IsImplicit) (Syntax: 'c with { X = 2 }') Instance Receiver: ILocalReferenceOperation: c (OperationKind.LocalReference, Type: C) (Syntax: 'c') Arguments(0) @@ -2667,7 +2670,7 @@ public static void Main() IWithOperation (OperationKind.With, Type: C, IsInvalid) (Syntax: 'c with { 5 }') Operand: ILocalReferenceOperation: c (OperationKind.LocalReference, Type: C) (Syntax: 'c') - CloneMethod: C C.<>Clone() + CloneMethod: C C." + WellKnownMemberNames.CloneMethodName + @"() Initializer: IObjectOrCollectionInitializerOperation (OperationKind.ObjectOrCollectionInitializer, Type: C, IsInvalid) (Syntax: '{ 5 }') Initializers(1): @@ -2680,7 +2683,7 @@ public static void Main() IWithOperation (OperationKind.With, Type: C, IsInvalid) (Syntax: 'c with { ') Operand: ILocalReferenceOperation: c (OperationKind.LocalReference, Type: C) (Syntax: 'c') - CloneMethod: C C.<>Clone() + CloneMethod: C C." + WellKnownMemberNames.CloneMethodName + @"() Initializer: IObjectOrCollectionInitializerOperation (OperationKind.ObjectOrCollectionInitializer, Type: C, IsInvalid) (Syntax: '{ ') Initializers(0)"); @@ -3329,7 +3332,7 @@ public C M(C c) => c with // Code size 33 (0x21) .maxstack 3 IL_0000: ldarg.1 - IL_0001: callvirt ""C C.<>Clone()"" + IL_0001: callvirt ""C C." + WellKnownMemberNames.CloneMethodName + @"()"" IL_0006: dup IL_0007: ldc.i4.5 IL_0008: callvirt ""void C.X.set"" @@ -3379,7 +3382,7 @@ .maxstack 3 IL_000f: callvirt ""ref int C.X.get"" IL_0014: ldind.i4 IL_0015: call ""void System.Console.WriteLine(int)"" - IL_001a: callvirt ""C C.<>Clone()"" + IL_001a: callvirt ""C C." + WellKnownMemberNames.CloneMethodName + @"()"" IL_001f: dup IL_0020: callvirt ""ref int C.X.get"" IL_0025: ldc.i4.1 @@ -3704,7 +3707,7 @@ public void Inheritance_09() var actualMembers = comp.GetMember("C").GetMembers().ToTestDisplayStrings(); var expectedMembers = new[] { - "C C.<>Clone()", + "C C." + WellKnownMemberNames.CloneMethodName + "()", "System.Type C.EqualityContract.get", "System.Type C.EqualityContract { get; }", "C..ctor(System.Int32 X, System.Int32 Y)", @@ -4215,7 +4218,7 @@ record C(object P) var expectedMembers = new[] { - "A B.<>Clone()", + "A B." + WellKnownMemberNames.CloneMethodName + "()", "System.Type B.EqualityContract.get", "System.Type B.EqualityContract { get; }", "B..ctor(System.Object P, System.Object Q)", @@ -4238,7 +4241,7 @@ record C(object P) expectedMembers = new[] { - "C C.<>Clone()", + "C C." + WellKnownMemberNames.CloneMethodName + "()", "System.Type C.EqualityContract.get", "System.Type C.EqualityContract { get; }", "C..ctor(System.Object P)", @@ -5466,7 +5469,7 @@ .method family hidebysig specialname rtspecialname instance void .ctor() ret } .method family hidebysig specialname rtspecialname instance void .ctor(class A A_1) { ldnull throw } - .method public hidebysig newslot specialname abstract virtual instance class A '<>Clone'() { } + .method public hidebysig newslot specialname abstract virtual instance class A '" + WellKnownMemberNames.CloneMethodName + @"'() { } .property instance class [mscorlib]System.Type EqualityContract() { .get instance class [mscorlib]System.Type A::get_EqualityContract() @@ -5500,7 +5503,7 @@ .method family hidebysig specialname rtspecialname instance void .ctor() ret } .method family hidebysig specialname rtspecialname instance void .ctor(class B A_1) { ldnull throw } - .method public hidebysig specialname abstract virtual instance class A '<>Clone'() { } + .method public hidebysig specialname abstract virtual instance class A '" + WellKnownMemberNames.CloneMethodName + @"'() { } .property instance class [mscorlib]System.Type EqualityContract() { .get instance class [mscorlib]System.Type B::get_EqualityContract() @@ -5560,7 +5563,7 @@ .method family hidebysig specialname rtspecialname instance void .ctor() ret } .method family hidebysig specialname rtspecialname instance void .ctor(class A A_1) { ldnull throw } - .method public hidebysig newslot specialname abstract virtual instance class A '<>Clone'() { } + .method public hidebysig newslot specialname abstract virtual instance class A '" + WellKnownMemberNames.CloneMethodName + @"'() { } .property instance class [mscorlib]System.Type EqualityContract() { .get instance class [mscorlib]System.Type A::GetProperty1() @@ -5634,7 +5637,7 @@ .method family hidebysig specialname rtspecialname instance void .ctor() ret } .method family hidebysig specialname rtspecialname instance void .ctor(class A A_1) { ldnull throw } - .method public hidebysig newslot specialname abstract virtual instance class A '<>Clone'() { } + .method public hidebysig newslot specialname abstract virtual instance class A '" + WellKnownMemberNames.CloneMethodName + @"'() { } .property instance class [mscorlib]System.Type EqualityContract() { .get instance class [mscorlib]System.Type A::'EqualityContract<>get'() @@ -5728,7 +5731,7 @@ .method family hidebysig specialname rtspecialname instance void .ctor() ret } .method family hidebysig specialname rtspecialname instance void .ctor(class A A_1) { ldnull throw } - .method public hidebysig newslot specialname abstract virtual instance class A '<>Clone'() { } + .method public hidebysig newslot specialname abstract virtual instance class A '" + WellKnownMemberNames.CloneMethodName + @"'() { } .property instance class [mscorlib]System.Type modopt(int32) EqualityContract() { .get instance class [mscorlib]System.Type modopt(int32) A::get_EqualityContract() @@ -5851,7 +5854,7 @@ .method family hidebysig specialname rtspecialname instance void .ctor() ret } .method family hidebysig specialname rtspecialname instance void .ctor(class A A_1) { ldnull throw } - .method public hidebysig newslot specialname virtual instance class A '<>Clone'() { ldnull throw } + .method public hidebysig newslot specialname virtual instance class A '" + WellKnownMemberNames.CloneMethodName + @"'() { ldnull throw } .property instance object P() { .get instance object A::get_P() @@ -6795,7 +6798,7 @@ public void CopyCtor_MissingInMetadata() var ilSource = @" .class public auto ansi beforefieldinit B extends [mscorlib]System.Object { - .method public hidebysig specialname newslot virtual instance class B '<>Clone' () cil managed + .method public hidebysig specialname newslot virtual instance class B '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { IL_0000: ldnull IL_0001: throw @@ -6870,7 +6873,7 @@ public void CopyCtor_InaccessibleInMetadata() var ilSource = @" .class public auto ansi beforefieldinit B extends [mscorlib]System.Object { - .method public hidebysig specialname newslot virtual instance class B '<>Clone' () cil managed + .method public hidebysig specialname newslot virtual instance class B '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { IL_0000: ldnull IL_0001: throw @@ -6939,7 +6942,7 @@ .class public auto ansi beforefieldinit B extends [mscorlib]System.Object { INJECT - .method public hidebysig specialname newslot virtual instance class B '<>Clone' () cil managed + .method public hidebysig specialname newslot virtual instance class B '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { IL_0000: ldarg.0 IL_0001: newobj instance void B::.ctor(class B) @@ -7126,7 +7129,7 @@ .method family hidebysig specialname rtspecialname instance void .ctor ( class B IL_000a: ret } - .method public hidebysig specialname newslot virtual instance class B`1 '<>Clone' () cil managed + .method public hidebysig specialname newslot virtual instance class B`1 '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { IL_0000: ldarg.0 IL_0001: newobj instance void class B`1::.ctor(class B`1) @@ -8449,7 +8452,7 @@ record B(int X, int Y) : A var actualMembers = comp.GetMember("B").GetMembers().ToTestDisplayStrings(); var expectedMembers = new[] { - "A B.<>Clone()", + "A B." + WellKnownMemberNames.CloneMethodName + "()", "System.Type B.EqualityContract.get", "System.Type B.EqualityContract { get; }", "B..ctor(System.Int32 X, System.Int32 Y)", @@ -8500,7 +8503,7 @@ record B(int X, int Y) : A var actualMembers = comp.GetMember("B").GetMembers().ToTestDisplayStrings(); var expectedMembers = new[] { - "A B.<>Clone()", + "A B." + WellKnownMemberNames.CloneMethodName + "()", "System.Type B.EqualityContract.get", "System.Type B.EqualityContract { get; }", "B..ctor(System.Int32 X, System.Int32 Y)", @@ -8531,13 +8534,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public final hidebysig virtual instance bool Equals ( @@ -8625,13 +8628,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public newslot hidebysig virtual instance bool Equals ( @@ -8719,13 +8722,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public newslot hidebysig instance bool Equals ( @@ -8813,13 +8816,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public newslot hidebysig virtual instance int32 Equals ( @@ -8984,13 +8987,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -9156,13 +9159,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -9267,13 +9270,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -9519,13 +9522,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -9624,13 +9627,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -9722,13 +9725,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -10053,13 +10056,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -10147,13 +10150,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -10241,13 +10244,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -10335,13 +10338,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -10425,13 +10428,13 @@ extends A { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -11711,13 +11714,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -11873,13 +11876,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -12000,13 +12003,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -12113,13 +12116,13 @@ extends System.Object { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -12192,13 +12195,13 @@ extends A { // Methods .method public hidebysig specialname newslot virtual - instance class A '<>Clone' () cil managed + instance class A '" + WellKnownMemberNames.CloneMethodName + @"' () cil managed { .maxstack 8 IL_0000: ldnull IL_0001: throw - } // end of method A::'<>Clone' + } // end of method A::'" + WellKnownMemberNames.CloneMethodName + @"' .method public hidebysig virtual instance bool Equals ( @@ -12493,7 +12496,7 @@ .locals init (C V_0, //c IL_0007: callvirt ""void C.X.init"" IL_000c: stloc.0 IL_000d: ldloc.0 - IL_000e: callvirt ""C C.<>Clone()"" + IL_000e: callvirt ""C C." + WellKnownMemberNames.CloneMethodName + @"()"" IL_0013: dup IL_0014: ldc.i4.2 IL_0015: callvirt ""void C.X.init"" @@ -12509,7 +12512,7 @@ .locals init (C V_0, //c IL_0037: callvirt ""void C.X.init"" IL_003c: stloc.1 IL_003d: ldloc.1 - IL_003e: callvirt ""C C.<>Clone()"" + IL_003e: callvirt ""C C." + WellKnownMemberNames.CloneMethodName + @"()"" IL_0043: castclass ""D"" IL_0048: dup IL_0049: ldc.i4.2 @@ -12549,13 +12552,13 @@ .locals init (C V_0, //c IL_00b3: ldloc.2 IL_00b4: stloc.s V_4 IL_00b6: ldloc.3 - IL_00b7: callvirt ""C C.<>Clone()"" + IL_00b7: callvirt ""C C." + WellKnownMemberNames.CloneMethodName + @"()"" IL_00bc: dup IL_00bd: ldc.i4.3 IL_00be: callvirt ""void C.X.init"" IL_00c3: stloc.3 IL_00c4: ldloc.s V_4 - IL_00c6: callvirt ""C C.<>Clone()"" + IL_00c6: callvirt ""C C." + WellKnownMemberNames.CloneMethodName + @"()"" IL_00cb: dup IL_00cc: ldc.i4.4 IL_00cd: callvirt ""void C.X.init"" @@ -14343,9 +14346,9 @@ .maxstack 2 VerifyVirtualMethod(comp.GetMember("B.get_EqualityContract"), isOverride: true); VerifyVirtualMethod(comp.GetMember("C.get_EqualityContract"), isOverride: true); - VerifyVirtualMethod(comp.GetMember("A.<>Clone"), isOverride: false); - VerifyVirtualMethod(comp.GetMember("B.<>Clone"), isOverride: true); - VerifyVirtualMethod(comp.GetMember("C.<>Clone"), isOverride: true); + VerifyVirtualMethod(comp.GetMember("A." + WellKnownMemberNames.CloneMethodName), isOverride: false); + VerifyVirtualMethod(comp.GetMember("B." + WellKnownMemberNames.CloneMethodName), isOverride: true); + VerifyVirtualMethod(comp.GetMember("C." + WellKnownMemberNames.CloneMethodName), isOverride: true); VerifyVirtualMethod(comp.GetMember("A.GetHashCode"), isOverride: true); VerifyVirtualMethod(comp.GetMember("B.GetHashCode"), isOverride: true); @@ -14787,7 +14790,7 @@ record C : B; var actualMembers = comp.GetMember("B").GetMembers().ToTestDisplayStrings(); var expectedMembers = new[] { - "A B.<>Clone()", + "A B." + WellKnownMemberNames.CloneMethodName + "()", "System.Type B.EqualityContract { get; }", "System.Type B.EqualityContract.get", "System.Int32 B.GetHashCode()", @@ -14913,7 +14916,7 @@ static void Main() var actualMembers = comp.GetMember("B1").GetMembers().ToTestDisplayStrings(); var expectedMembers = new[] { - "A B1.<>Clone()", + "A B1." + WellKnownMemberNames.CloneMethodName + "()", "System.Type B1.EqualityContract.get", "System.Type B1.EqualityContract { get; }", "B1..ctor(System.Int32 P)", diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs index 8b5212d81f704..4c8f0e9c3f4e2 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs @@ -39,6 +39,8 @@ public void Simple_01() Assert.Same(entryPoint, comp.GetEntryPoint(default)); Assert.False(entryPoint.CanBeReferencedByName); Assert.False(entryPoint.ContainingType.CanBeReferencedByName); + Assert.Equal("
$", entryPoint.Name); + Assert.Equal("$", entryPoint.ContainingType.Name); } private static void AssertEntryPointParameter(SynthesizedSimpleProgramEntryPointSymbol entryPoint) @@ -6053,13 +6055,13 @@ void validateAssembly(PEAssembly assembly) var methodName = peReader.GetString(methodDef.Name); var expectedFlags = methodName switch { - "<$Main>g__forwardRef|0_0" => MethodImplAttributes.ForwardRef, - "<$Main>g__noInlining|0_1" => MethodImplAttributes.NoInlining, - "<$Main>g__noOptimization|0_2" => MethodImplAttributes.NoOptimization, - "<$Main>g__synchronized|0_3" => MethodImplAttributes.Synchronized, - "<$Main>g__internalCallStatic|0_4" => MethodImplAttributes.InternalCall, + "<" + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName + ">g__forwardRef|0_0" => MethodImplAttributes.ForwardRef, + "<" + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName + ">g__noInlining|0_1" => MethodImplAttributes.NoInlining, + "<" + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName + ">g__noOptimization|0_2" => MethodImplAttributes.NoOptimization, + "<" + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName + ">g__synchronized|0_3" => MethodImplAttributes.Synchronized, + "<" + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName + ">g__internalCallStatic|0_4" => MethodImplAttributes.InternalCall, ".ctor" => MethodImplAttributes.IL, - "$Main" => MethodImplAttributes.IL, + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName => MethodImplAttributes.IL, _ => throw TestExceptionUtilities.UnexpectedValue(methodName) }; @@ -6108,12 +6110,12 @@ public void Attributes_03() void validate(ModuleSymbol module) { - var cClass = module.GlobalNamespace.GetMember(SimpleProgramNamedTypeSymbol.UnspeakableName); + var cClass = module.GlobalNamespace.GetMember(WellKnownMemberNames.TopLevelStatementsEntryPointTypeName); Assert.Equal(new[] { "CompilerGeneratedAttribute" }, GetAttributeNames(cClass.GetAttributes().As())); - Assert.Empty(cClass.GetMethod(SynthesizedSimpleProgramEntryPointSymbol.UnspeakableName).GetAttributes()); + Assert.Empty(cClass.GetMethod(WellKnownMemberNames.TopLevelStatementsEntryPointMethodName).GetAttributes()); - var localFn1 = cClass.GetMethod("<$Main>g__local1|0_0"); + var localFn1 = cClass.GetMethod("<" + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName + ">g__local1|0_0"); Assert.Empty(localFn1.GetAttributes()); validateLocalFunction(localFn1); @@ -6572,7 +6574,7 @@ private void Handle1(SymbolStartAnalysisContext context) private void Handle2(SymbolStartAnalysisContext context) { - Assert.Equal(SimpleProgramNamedTypeSymbol.UnspeakableName, context.Symbol.ToTestDisplayString()); + Assert.Equal(WellKnownMemberNames.TopLevelStatementsEntryPointTypeName, context.Symbol.ToTestDisplayString()); Interlocked.Increment(ref FireCount3); context.RegisterSymbolEndAction(Handle5); @@ -6609,7 +6611,7 @@ private void Handle4(SymbolAnalysisContext context) private void Handle5(SymbolAnalysisContext context) { - Assert.Equal(SimpleProgramNamedTypeSymbol.UnspeakableName, context.Symbol.ToTestDisplayString()); + Assert.Equal(WellKnownMemberNames.TopLevelStatementsEntryPointTypeName, context.Symbol.ToTestDisplayString()); Interlocked.Increment(ref FireCount8); } } @@ -7256,7 +7258,7 @@ private void Handle3(SymbolAnalysisContext context) case "C1": Interlocked.Increment(ref FireCount3); break; - case SimpleProgramNamedTypeSymbol.UnspeakableName: + case WellKnownMemberNames.TopLevelStatementsEntryPointTypeName: Interlocked.Increment(ref FireCount4); break; default: @@ -7593,14 +7595,14 @@ public void Return_01() { _ = ConditionalSkipReason.NativePdbRequiresDesktop; - comp.VerifyPdb("$Program.$Main", -@" + comp.VerifyPdb(WellKnownMemberNames.TopLevelStatementsEntryPointTypeName + "." + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName, +@$" - + - + @@ -7616,6 +7618,11 @@ public void Return_01() } } + private static string EscapeForXML(string toEscape) + { + return toEscape.Replace("<", "<").Replace(">", ">"); + } + [Fact] public void Return_02() { @@ -7635,14 +7642,14 @@ public void Return_02() { _ = ConditionalSkipReason.NativePdbRequiresDesktop; - comp.VerifyPdb("$Program.$Main", -@" + comp.VerifyPdb(WellKnownMemberNames.TopLevelStatementsEntryPointTypeName + "." + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName, +@$" - + - + @@ -7682,16 +7689,16 @@ public void Return_03() { _ = ConditionalSkipReason.NativePdbRequiresDesktop; - comp.VerifyPdb("$Program+<$Main>d__0.MoveNext", -@" + comp.VerifyPdb(WellKnownMemberNames.TopLevelStatementsEntryPointTypeName + "+<" + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName + ">d__0.MoveNext", +@$" - + - + - + @@ -7712,8 +7719,8 @@ public void Return_03() - - + + @@ -7745,16 +7752,16 @@ public void Return_04() { _ = ConditionalSkipReason.NativePdbRequiresDesktop; - comp.VerifyPdb("$Program+<$Main>d__0.MoveNext", -@" + comp.VerifyPdb(WellKnownMemberNames.TopLevelStatementsEntryPointTypeName + "+<" + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName + ">d__0.MoveNext", +@$" - + - + - + @@ -7776,8 +7783,8 @@ public void Return_04() - - + + @@ -8214,7 +8221,7 @@ public void ThrowStatement_02() var comp = CreateCompilation(text, options: TestOptions.DebugExe, parseOptions: DefaultParseOptions); comp.VerifyEmitDiagnostics(); - CompileAndVerify(comp).VerifyIL("", sequencePoints: "$Program.$Main", source: text, expectedIL: + CompileAndVerify(comp).VerifyIL("", sequencePoints: WellKnownMemberNames.TopLevelStatementsEntryPointTypeName + "." + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName, source: text, expectedIL: @" { // Code size 2 (0x2) @@ -8292,7 +8299,7 @@ public void CheckedStatement_01() "; var comp = CreateCompilation(text, options: TestOptions.DebugExe, parseOptions: DefaultParseOptions); comp.VerifyEmitDiagnostics(); - CompileAndVerify(comp, expectedOutput: "3").VerifyIL("", sequencePoints: "$Program.$Main", source: text, expectedIL: + CompileAndVerify(comp, expectedOutput: "3").VerifyIL("", sequencePoints: WellKnownMemberNames.TopLevelStatementsEntryPointTypeName + "." + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName, source: text, expectedIL: @" { // Code size 20 (0x14) @@ -8339,7 +8346,7 @@ public void UncheckedStatement_01() "; var comp = CreateCompilation(text, options: TestOptions.DebugExe.WithOverflowChecks(true), parseOptions: DefaultParseOptions); comp.VerifyEmitDiagnostics(); - CompileAndVerify(comp, expectedOutput: "3").VerifyIL("", sequencePoints: "$Program.$Main", source: text, expectedIL: + CompileAndVerify(comp, expectedOutput: "3").VerifyIL("", sequencePoints: WellKnownMemberNames.TopLevelStatementsEntryPointTypeName + "." + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName, source: text, expectedIL: @" { // Code size 20 (0x14) diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelAPITests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelAPITests.cs index cb5c9417a9c96..fe13548b9a2c9 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelAPITests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelAPITests.cs @@ -813,7 +813,7 @@ public class A var typeA = mems.Where(s => s.Name == "A").Select(s => s); Assert.Equal(1, typeA.Count()); - var invalid = mems.Where(s => s.Name == SimpleProgramNamedTypeSymbol.UnspeakableName).Select(s => s); + var invalid = mems.Where(s => s.Name == WellKnownMemberNames.TopLevelStatementsEntryPointTypeName).Select(s => s); Assert.Equal(1, invalid.Count()); } diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/RecordTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/RecordTests.cs index be448d6fe80de..4a5ab7c5cced1 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/RecordTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/RecordTests.cs @@ -1056,7 +1056,7 @@ record C }"); var members = comp.GlobalNamespace.GetTypeMember("C").GetMembers(); AssertEx.Equal(new[] { - "C! C.<>Clone()", + "C! C." + WellKnownMemberNames.CloneMethodName + "()", "System.Type! C.EqualityContract.get", "System.Type! C.EqualityContract { get; }", "System.Int32 C.k__BackingField", @@ -1429,7 +1429,7 @@ public static void Main() Assert.True(clone.IsAbstract); Assert.Equal(0, clone.ParameterCount); Assert.Equal(0, clone.Arity); - Assert.Equal("R R.<>Clone()", clone.ToTestDisplayString()); + Assert.Equal("R R." + WellKnownMemberNames.CloneMethodName + "()", clone.ToTestDisplayString()); var r2 = comp.GlobalNamespace.GetTypeMember("R2"); var clone2 = (MethodSymbol)r2.GetMembers(WellKnownMemberNames.CloneMethodName).Single(); @@ -1439,7 +1439,7 @@ public static void Main() Assert.Equal(0, clone2.ParameterCount); Assert.Equal(0, clone2.Arity); Assert.True(clone2.OverriddenMethod.Equals(clone, TypeCompareKind.ConsiderEverything)); - Assert.Equal("R R2.<>Clone()", clone2.ToTestDisplayString()); + Assert.Equal("R R2." + WellKnownMemberNames.CloneMethodName + "()", clone2.ToTestDisplayString()); var r3 = comp.GlobalNamespace.GetTypeMember("R3"); var clone3 = (MethodSymbol)r3.GetMembers(WellKnownMemberNames.CloneMethodName).Single(); @@ -1449,7 +1449,7 @@ public static void Main() Assert.Equal(0, clone3.ParameterCount); Assert.Equal(0, clone3.Arity); Assert.True(clone3.OverriddenMethod.Equals(clone2, TypeCompareKind.ConsiderEverything)); - Assert.Equal("R R3.<>Clone()", clone3.ToTestDisplayString()); + Assert.Equal("R R3." + WellKnownMemberNames.CloneMethodName + "()", clone3.ToTestDisplayString()); var r4 = comp.GlobalNamespace.GetTypeMember("R4"); var clone4 = (MethodSymbol)r4.GetMembers(WellKnownMemberNames.CloneMethodName).Single(); @@ -1459,7 +1459,7 @@ public static void Main() Assert.Equal(0, clone4.ParameterCount); Assert.Equal(0, clone4.Arity); Assert.True(clone4.OverriddenMethod.Equals(clone3, TypeCompareKind.ConsiderEverything)); - Assert.Equal("R R4.<>Clone()", clone4.ToTestDisplayString()); + Assert.Equal("R R4." + WellKnownMemberNames.CloneMethodName + "()", clone4.ToTestDisplayString()); var r5 = comp.GlobalNamespace.GetTypeMember("R5"); var clone5 = (MethodSymbol)r5.GetMembers(WellKnownMemberNames.CloneMethodName).Single(); @@ -1469,7 +1469,7 @@ public static void Main() Assert.Equal(0, clone5.ParameterCount); Assert.Equal(0, clone5.Arity); Assert.True(clone5.OverriddenMethod.Equals(clone4, TypeCompareKind.ConsiderEverything)); - Assert.Equal("R R5.<>Clone()", clone5.ToTestDisplayString()); + Assert.Equal("R R5." + WellKnownMemberNames.CloneMethodName + "()", clone5.ToTestDisplayString()); var verifier = CompileAndVerify(comp, expectedOutput: "", verify: Verification.Passes); verifier.VerifyIL("C.Main", @" @@ -1477,10 +1477,10 @@ public static void Main() // Code size 28 (0x1c) .maxstack 1 IL_0000: newobj ""R3..ctor()"" - IL_0005: callvirt ""R R.<>Clone()"" + IL_0005: callvirt ""R R." + WellKnownMemberNames.CloneMethodName + @"()"" IL_000a: pop IL_000b: newobj ""R5..ctor()"" - IL_0010: callvirt ""R R.<>Clone()"" + IL_0010: callvirt ""R R." + WellKnownMemberNames.CloneMethodName + @"()"" IL_0015: castclass ""R4"" IL_001a: pop IL_001b: ret diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/TypeTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/TypeTests.cs index 978c52fa45df2..ccd3d0fa64368 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/TypeTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/TypeTests.cs @@ -1450,7 +1450,7 @@ public void ErrorTypeTest01() var errSymbol = comp.SourceModule.GlobalNamespace.GetMembers().FirstOrDefault() as NamedTypeSymbol; Assert.NotNull(errSymbol); - Assert.Equal(SimpleProgramNamedTypeSymbol.UnspeakableName, errSymbol.Name); + Assert.Equal(WellKnownMemberNames.TopLevelStatementsEntryPointTypeName, errSymbol.Name); Assert.False(errSymbol.IsErrorType(), "ErrorType"); Assert.False(errSymbol.IsImplicitClass, "ImplicitClass"); } diff --git a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt index 509091ff40f33..c442b983ab05f 100644 --- a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt +++ b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt @@ -45,6 +45,8 @@ Microsoft.CodeAnalysis.Operations.IWithOperation.Operand.get -> Microsoft.CodeAn Microsoft.CodeAnalysis.SymbolKind.FunctionPointerType = 20 -> Microsoft.CodeAnalysis.SymbolKind Microsoft.CodeAnalysis.TypeKind.FunctionPointer = 13 -> Microsoft.CodeAnalysis.TypeKind abstract Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptionsProvider.GlobalOptions.get -> Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptions +const Microsoft.CodeAnalysis.WellKnownMemberNames.TopLevelStatementsEntryPointMethodName = "
$" -> string +const Microsoft.CodeAnalysis.WellKnownMemberNames.TopLevelStatementsEntryPointTypeName = "$" -> string static Microsoft.CodeAnalysis.AnalyzerConfigSet.Create(TList analyzerConfigs, out System.Collections.Immutable.ImmutableArray diagnostics) -> Microsoft.CodeAnalysis.AnalyzerConfigSet virtual Microsoft.CodeAnalysis.Operations.OperationVisitor.VisitBinaryPattern(Microsoft.CodeAnalysis.Operations.IBinaryPatternOperation operation) -> void virtual Microsoft.CodeAnalysis.Operations.OperationVisitor.VisitNegatedPattern(Microsoft.CodeAnalysis.Operations.INegatedPatternOperation operation) -> void diff --git a/src/Compilers/Core/Portable/Symbols/WellKnownMemberNames.cs b/src/Compilers/Core/Portable/Symbols/WellKnownMemberNames.cs index 7e9eabd7ac23e..692b38b5febf5 100644 --- a/src/Compilers/Core/Portable/Symbols/WellKnownMemberNames.cs +++ b/src/Compilers/Core/Portable/Symbols/WellKnownMemberNames.cs @@ -344,6 +344,16 @@ public static class WellKnownMemberNames public const string SliceMethodName = "Slice"; // internal until we settle on this long-term - internal const string CloneMethodName = "<>Clone"; + internal const string CloneMethodName = "$"; + + /// + /// The name of an entry point method synthesized for top-level statements. + /// + public const string TopLevelStatementsEntryPointMethodName = "
$"; + + /// + /// The name of a type synthesized for a top-level statements entry point method. + /// + public const string TopLevelStatementsEntryPointTypeName = "$"; } }