Skip to content

Commit

Permalink
Ensure consistent scheme for unspeakable names.
Browse files Browse the repository at this point in the history
Closes dotnet#45564.
Related to dotnet#45110.
  • Loading branch information
AlekseyTs committed Jul 14, 2020
1 parent 0535a47 commit 9f56803
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "<Main>$") && // 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 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
/// </summary>
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.
}
Expand All @@ -42,7 +40,7 @@ internal SimpleProgramNamedTypeSymbol(NamespaceSymbol globalNamespace, MergedTyp

private static SimpleProgramNamedTypeSymbol? GetSimpleProgramNamedTypeSymbol(CSharpCompilation compilation)
{
return compilation.SourceModule.GlobalNamespace.GetTypeMembers(UnspeakableName).OfType<SimpleProgramNamedTypeSymbol>().SingleOrDefault();
return compilation.SourceModule.GlobalNamespace.GetTypeMembers(WellKnownMemberNames.TopLevelStatementsEntryPointTypeName).OfType<SimpleProgramNamedTypeSymbol>().SingleOrDefault();
}

internal static SynthesizedSimpleProgramEntryPointSymbol? GetSimpleProgramEntryPoint(CSharpCompilation compilation, CompilationUnitSyntax compilationUnit, bool fallbackToMainEntryPoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
internal sealed class SynthesizedSimpleProgramEntryPointSymbol : SourceMemberMethodSymbol
{
internal const string UnspeakableName = "$Main";

/// <summary>
/// The corresponding <see cref="SingleTypeDeclaration"/>.
/// </summary>
Expand Down Expand Up @@ -73,7 +71,7 @@ public override string Name
{
get
{
return UnspeakableName;
return WellKnownMemberNames.TopLevelStatementsEntryPointMethodName;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ void local(Func<nint, nint> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,7 @@ void M() { }

var cMembers = comp.GlobalNamespace.GetMember<NamedTypeSymbol>("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)",
Expand Down
Loading

0 comments on commit 9f56803

Please sign in to comment.