Skip to content

Commit e2ed258

Browse files
authored
Ensure consistent scheme for unspeakable names. (#45930)
Closes #45564. Related to #45110.
1 parent fad977f commit e2ed258

File tree

13 files changed

+167
-148
lines changed

13 files changed

+167
-148
lines changed

src/Analyzers/Core/Analyzers/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,8 @@ private bool IsCandidateSymbol(ISymbol memberSymbol)
696696
}
697697

698698
private bool IsEntryPoint(IMethodSymbol methodSymbol)
699-
=> (methodSymbol.Name == WellKnownMemberNames.EntryPointMethodName || methodSymbol.Name == "$Main") &&
699+
=> (methodSymbol.Name == WellKnownMemberNames.EntryPointMethodName || methodSymbol.Name == "<Main>$") && // https://github.com/dotnet/roslyn/issues/45110 Switch to using WellKnownMemberNames.TopLevelStatementsEntryPointMethodName
700+
// once src\CodeStyle\Core\Analyzers\Microsoft.CodeAnalysis.CodeStyle.csproj is able to use the latest version of the type.
700701
methodSymbol.IsStatic &&
701702
(methodSymbol.ReturnsVoid ||
702703
methodSymbol.ReturnType.SpecialType == SpecialType.System_Int32 ||

src/Compilers/CSharp/Portable/Declarations/DeclarationTreeBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private static SingleNamespaceOrTypeDeclaration CreateSimpleProgram(GlobalStatem
131131
{
132132
return new SingleTypeDeclaration(
133133
kind: DeclarationKind.SimpleProgram,
134-
name: SimpleProgramNamedTypeSymbol.UnspeakableName,
134+
name: WellKnownMemberNames.TopLevelStatementsEntryPointTypeName,
135135
arity: 0,
136136
modifiers: DeclarationModifiers.Internal | DeclarationModifiers.Partial | DeclarationModifiers.Static,
137137
declFlags: (hasAwaitExpressions ? SingleTypeDeclaration.TypeDeclarationFlags.HasAwaitExpressions : SingleTypeDeclaration.TypeDeclarationFlags.None) |

src/Compilers/CSharp/Portable/Symbols/Source/SimpleProgramNamedTypeSymbol.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
2323
/// </summary>
2424
internal sealed class SimpleProgramNamedTypeSymbol : SourceMemberContainerTypeSymbol
2525
{
26-
internal const string UnspeakableName = "$Program";
27-
2826
internal SimpleProgramNamedTypeSymbol(NamespaceSymbol globalNamespace, MergedTypeDeclaration declaration, DiagnosticBag diagnostics)
2927
: base(globalNamespace, declaration, diagnostics)
3028
{
3129
Debug.Assert(globalNamespace.IsGlobalNamespace);
3230
Debug.Assert(declaration.Kind == DeclarationKind.SimpleProgram);
33-
Debug.Assert(declaration.Name == UnspeakableName);
31+
Debug.Assert(declaration.Name == WellKnownMemberNames.TopLevelStatementsEntryPointTypeName);
3432

3533
state.NotePartComplete(CompletionPart.EnumUnderlyingType); // No work to do for this.
3634
}
@@ -42,7 +40,7 @@ internal SimpleProgramNamedTypeSymbol(NamespaceSymbol globalNamespace, MergedTyp
4240

4341
private static SimpleProgramNamedTypeSymbol? GetSimpleProgramNamedTypeSymbol(CSharpCompilation compilation)
4442
{
45-
return compilation.SourceModule.GlobalNamespace.GetTypeMembers(UnspeakableName).OfType<SimpleProgramNamedTypeSymbol>().SingleOrDefault();
43+
return compilation.SourceModule.GlobalNamespace.GetTypeMembers(WellKnownMemberNames.TopLevelStatementsEntryPointTypeName).OfType<SimpleProgramNamedTypeSymbol>().SingleOrDefault();
4644
}
4745

4846
internal static SynthesizedSimpleProgramEntryPointSymbol? GetSimpleProgramEntryPoint(CSharpCompilation compilation, CompilationUnitSyntax compilationUnit, bool fallbackToMainEntryPoint)

src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
1818
{
1919
internal sealed class SynthesizedSimpleProgramEntryPointSymbol : SourceMemberMethodSymbol
2020
{
21-
internal const string UnspeakableName = "$Main";
22-
2321
/// <summary>
2422
/// The corresponding <see cref="SingleTypeDeclaration"/>.
2523
/// </summary>
@@ -73,7 +71,7 @@ public override string Name
7371
{
7472
get
7573
{
76-
return UnspeakableName;
74+
return WellKnownMemberNames.TopLevelStatementsEntryPointMethodName;
7775
}
7876
}
7977

src/Compilers/CSharp/Test/Semantic/Semantics/AnonymousFunctionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ void local(Func<nint, nint> fn)
12411241
{
12421242
Console.WriteLine(fn(0));
12431243
}";
1244-
VerifyInPreview(source, expectedOutput: "1", metadataName: "$Program.<>c.<$Main>b__0_0", expectedIL: @"
1244+
VerifyInPreview(source, expectedOutput: "1", metadataName: WellKnownMemberNames.TopLevelStatementsEntryPointTypeName + ".<>c.<" + WellKnownMemberNames.TopLevelStatementsEntryPointMethodName + ">b__0_0", expectedIL: @"
12451245
{
12461246
// Code size 5 (0x5)
12471247
.maxstack 2

src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2173,7 +2173,7 @@ void M() { }
21732173

21742174
var cMembers = comp.GlobalNamespace.GetMember<NamedTypeSymbol>("C").GetMembers();
21752175
AssertEx.SetEqual(new[] {
2176-
"C C.<>Clone()",
2176+
"C C." + WellKnownMemberNames.CloneMethodName + "()",
21772177
"System.Type C.EqualityContract.get",
21782178
"System.Type C.EqualityContract { get; }",
21792179
"C..ctor(System.Int32 i)",

0 commit comments

Comments
 (0)