Skip to content

Commit

Permalink
Merge pull request #48173 from Youssef1313/patch-42
Browse files Browse the repository at this point in the history
Don't offer generate parameter/field/property for top-level programs
  • Loading branch information
CyrusNajmabadi authored Oct 1, 2020
2 parents 467f6ac + fa1e83a commit afd1030
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9342,5 +9342,12 @@ internal MyException(int error, int offset, string message) : base(message)
string.Format(FeaturesResources.Generate_parameter_0, "Error", "MyException"),
});
}

[WorkItem(48172, "https://github.com/dotnet/roslyn/issues/48172")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateVariable)]
public async Task TestMissingOfferParameterInTopLevel()
{
await TestMissingAsync("[|Console|].WriteLine();", new TestParameters(Options.Regular));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private async Task<bool> TryInitializeAsync(

internal bool CanGeneratePropertyOrField()
{
return !ContainingType.IsImplicitClass;
return ContainingType is { IsImplicitClass: false, Name: not WellKnownMemberNames.TopLevelStatementsEntryPointTypeName };
}

internal bool CanGenerateLocal()
Expand All @@ -148,7 +148,9 @@ internal bool CanGenerateLocal()
internal bool CanGenerateParameter()
{
// !this.IsInMemberContext prevents us offering this fix for `x.goo` where `goo` does not exist
return ContainingMethod != null && !IsInMemberContext && !IsConstant;
// Workaround: The compiler returns IsImplicitlyDeclared = false for <Main>$.
return ContainingMethod is { IsImplicitlyDeclared: false, Name: not WellKnownMemberNames.TopLevelStatementsEntryPointMethodName }
&& !IsInMemberContext && !IsConstant;
}

private bool TryInitializeExplicitInterface(
Expand Down

0 comments on commit afd1030

Please sign in to comment.