Skip to content

Move from calling Create to calling a specific constructor#53262

Merged
333fred merged 2 commits intodotnet:features/interpolated-stringfrom
333fred:constructor-call
May 12, 2021
Merged

Move from calling Create to calling a specific constructor#53262
333fred merged 2 commits intodotnet:features/interpolated-stringfrom
333fred:constructor-call

Conversation

@333fred
Copy link
Copy Markdown
Member

@333fred 333fred commented May 7, 2021

Couple of smaller changes:

  1. Call a constructor, rather than a create method.
  2. Move from calling types builders to handlers, to keep in sync with API Proposal: C# 10 interpolated strings support, part 3 runtime#51962.

@ghost ghost added the Area-Compilers label May 7, 2021
@333fred 333fred changed the title constructor call Move from calling Create to calling a specific constructor May 7, 2021
@333fred 333fred force-pushed the constructor-call branch from a67c0c9 to a37f8ae Compare May 7, 2021 21:47
@333fred 333fred marked this pull request as ready for review May 7, 2021 21:49
@333fred 333fred requested a review from a team as a code owner May 7, 2021 21:49
@333fred 333fred requested review from AlekseyTs and chsienki May 7, 2021 21:49
@333fred
Copy link
Copy Markdown
Member Author

333fred commented May 7, 2021

@chsienki @AlekseyTs for review.

1 similar comment
@333fred
Copy link
Copy Markdown
Member Author

333fred commented May 10, 2021

@chsienki @AlekseyTs for review.

@chsienki chsienki self-assigned this May 11, 2021
Copy link
Copy Markdown
Member

@chsienki chsienki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@333fred
Copy link
Copy Markdown
Member Author

333fred commented May 11, 2021

@AlekseyTs for review.

/// <summary>
/// Helper method to create a synthesized constructor invocation.
/// </summary>
private BoundExpression MakeClassCreationExpression(
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs May 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MakeClassCreationExpression

The naming might be somewhat confusing. The helper isn't just for classes right? Structures are good too? You are probably follwong the pattern of BindClassCreationExpression name, however that function wasn't meant to be used as a general helper. Consider using name that simply indicates that an instance is created by using constructor. Then arguments start making more sense, etc. "MakeConstructorInvocation"? #Pending

}

private BoundExpression MakeBadExpressionForObjectCreation(SyntaxNode node, TypeSymbol type, AnalyzedArguments analyzedArguments, InitializerExpressionSyntax initializerOpt, SyntaxNode typeSyntax, BindingDiagnosticBag diagnostics)
/// <param name="typeSyntax">If <paramref name="initializerOpt"/> is not null, this should not be null.</param>
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs May 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If is not null, this should not be null.

Shouldn't be null if <paramref name="initializerOpt"/> is not null.? #Pending


BoundCall? createExpression = BindCreateCall(unconvertedInterpolatedString.Syntax, interpolatedStringBuilderType, arguments, diagnostics);
// PROTOTYPE(interp-string): Support optional out param for whether the builder was created successfully and passing in other required args
BoundExpression? createExpression = MakeClassCreationExpression(interpolatedStringBuilderType, arguments, unconvertedInterpolatedString.Syntax, diagnostics);
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs May 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MakeClassCreationExpression

BindCreateCall used to report an error unless it was producing a BoundCall node. Should we be doing something similar here? For BoundDynamicObjectCreationExpression, for example? #Pending

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a prototype comment in LocalLowering to handle dynamic at a later point. I'll add assert for now that it either HasErrors or is a constructor.


BoundCall? createExpression = BindCreateCall(unconvertedInterpolatedString.Syntax, interpolatedStringBuilderType, arguments, diagnostics);
// PROTOTYPE(interp-string): Support optional out param for whether the builder was created successfully and passing in other required args
BoundExpression? createExpression = MakeClassCreationExpression(interpolatedStringBuilderType, arguments, unconvertedInterpolatedString.Syntax, diagnostics);
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs May 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MakeClassCreationExpression

Does this handle optional parameters? #Closed

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 2)

@333fred
Copy link
Copy Markdown
Member Author

333fred commented May 12, 2021

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@333fred 333fred enabled auto-merge (squash) May 12, 2021 21:33
@333fred 333fred merged commit a4ebff3 into dotnet:features/interpolated-string May 12, 2021
@333fred 333fred deleted the constructor-call branch May 13, 2021 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants