Skip to content

Commit

Permalink
Merge pull request #72421 from sdelarosbil/support-primary-constructo…
Browse files Browse the repository at this point in the history
…r-base-speculative
  • Loading branch information
CyrusNajmabadi authored Mar 21, 2024
2 parents 2f72b4d + 5dc6451 commit d2b48fe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,23 @@ void X(int[] x) { }
}.RunAsync();
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/72337")]
public async Task TestTargetTypedArgumentPrimaryConstructor1()
{
await new VerifyCS.Test
{
TestCode = """
class C(int[] x);
class C2() : C([|[|new|] int[]|] { 1, 2, 3 });
""",
FixedCode = """
class C(int[] x);
class C2() : C([1, 2, 3]);
""",
LanguageVersion = LanguageVersion.CSharp12,
}.RunAsync();
}

[Fact]
public async Task TestNotTargetTypedArgument2()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public static bool CanSpeculateOnNode(SyntaxNode node)
SyntaxKind.ThisConstructorInitializer or
SyntaxKind.BaseConstructorInitializer or
SyntaxKind.EqualsValueClause or
SyntaxKind.ArrowExpressionClause;
SyntaxKind.ArrowExpressionClause or
SyntaxKind.PrimaryConstructorBaseType;

protected override void ValidateSpeculativeSemanticModel(SemanticModel speculativeSemanticModel, SyntaxNode nodeToSpeculate)
{
Expand Down Expand Up @@ -157,6 +158,10 @@ public static SemanticModel CreateSpeculativeSemanticModelForNode(SyntaxNode nod
case SyntaxKind.ArrowExpressionClause:
semanticModel.TryGetSpeculativeSemanticModel(position, (ArrowExpressionClauseSyntax)nodeToSpeculate, out speculativeModel);
return speculativeModel;

case SyntaxKind.PrimaryConstructorBaseType:
semanticModel.TryGetSpeculativeSemanticModel(position, (PrimaryConstructorBaseTypeSyntax)nodeToSpeculate, out speculativeModel);
return speculativeModel;
}

// CONSIDER: Do we care about this case?
Expand Down

0 comments on commit d2b48fe

Please sign in to comment.