Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11931,6 +11931,27 @@ public class C(int x) : Base(x)
End Using
End Function

<WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/78917")>
Public Async Function FilterPrimaryConstructorParameters_AllowInBaseTypeWhenCapturedAsMember() As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document><![CDATA[
public sealed class Derived(
string value)
: Base($"{val$$}")
{
public string Value { get; } = value;
}

public abstract class Base(string value);
]]>
</Document>,
languageVersion:=LanguageVersion.CSharp12)

state.SendInvokeCompletionList()
Await state.AssertCompletionItemsContain("value", displayTextSuffix:="")
End Using
End Function

<WpfFact, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function TestItemsSorted() As Task
Using state = TestStateFactory.CreateCSharpTestState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ static bool IsCapturedPrimaryConstructorParameter(
CancellationToken cancellationToken)
{
// Fine to offer primary constructor parameters in field/property initializers
var initializer = context.TargetToken.GetAncestors<EqualsValueClauseSyntax>().FirstOrDefault();
var initializer = context.TargetToken.GetAncestor<EqualsValueClauseSyntax>();
if (initializer is
{
Parent: PropertyDeclarationSyntax or
Expand All @@ -453,6 +453,11 @@ static bool IsCapturedPrimaryConstructorParameter(
return false;
}

// Also fine to offer primary constructor parameters in the base type list of that type.
var baseTypeSyntax = context.TargetToken.GetAncestor<PrimaryConstructorBaseTypeSyntax>();
if (baseTypeSyntax != null)
return false;

// We're not in an initializer. Filter out this primary constructor parameter if it's already been
// captured by an existing field or property initializer.

Expand Down
Loading