Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement binding and lowering for the with expression #43249

Merged
merged 8 commits into from
May 1, 2020

Conversation

agocke
Copy link
Member

@agocke agocke commented Apr 10, 2020

A with expression binds to a parameterless, accessible, instance method
called Clone on the receiver type.

Then, all arguments are bound against record properties with the same
name, and the expressions are assigned to the properties' backing
fields.

Relates to #40726 (test plan for records)

@agocke agocke force-pushed the with-binding branch 3 times, most recently from f523e34 to 08e8600 Compare April 10, 2020 18:39
A with expression binds to a parameterless, accessible, instance method
called Clone on the receiver type.

Then, all arguments are bound against record properties with the same
name, and the expressions are assigned to the properties' backing
fields.
@agocke agocke marked this pull request as ready for review April 10, 2020 19:59
@agocke agocke requested a review from a team as a code owner April 10, 2020 19:59
@gafter gafter self-requested a review April 10, 2020 20:30
@gafter gafter added this to the Compiler.Net5 milestone Apr 10, 2020
<data name="WRN_GeneratorFailedDuringGeneration" xml:space="preserve">
<value>Generator '{0}' failed to generate source. It will not contribute to the output and compilation errors may occur as a result.</value>
<data name="ERR_InvalidWithReceiverType" xml:space="preserve">
<value>The receiver of a `with` expression must have a valid non-void type.</value>
Copy link
Member

@gafter gafter Apr 10, 2020

Choose a reason for hiding this comment

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

valid [](start = 59, length = 5)

What does "valid" mean here? I suggest dropping the word. If it were an error type we presumably would not report this. #Resolved

@gafter
Copy link
Member

gafter commented Apr 10, 2020

There are a handful of parts of the specification that don't make sense to me, but I don't know where to put comments on it. I can't really review the implementation against a spec that I don't understand. #Resolved

@agocke
Copy link
Member Author

agocke commented Apr 10, 2020

I created a spec PR that we can use for discussion here: dotnet/csharplang#3353 #Resolved

@333fred
Copy link
Member

333fred commented Apr 22, 2020

Done review pass (commit 2)

Copy link
Member

@333fred 333fred 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 4), but it looks like you need to rerun the bound node generator.

@gafter
Copy link
Member

gafter commented Apr 23, 2020

Finished reviewing Iteration 4. #Resolved

@agocke
Copy link
Member Author

agocke commented Apr 27, 2020

@gafter I think I've addressed your comments

if (symbol is MethodSymbol { ParameterCount: 0 } m)
{
cloneMethod = m;
break;
Copy link
Member

@gafter gafter Apr 29, 2020

Choose a reason for hiding this comment

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

How does this handle multiple results? That can happen for example when Clone is overridden or hides another. This technique does not correspond to how invocations are handled, as there is no contract for the order of symbols in a lookup result. #Resolved

originalBinder: this,
diagnose: false,
useSiteDiagnostics: ref useSiteDiagnostics);
if (lookupResult.IsSingleViable &&
Copy link
Member

@gafter gafter Apr 29, 2020

Choose a reason for hiding this comment

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

IsSingleViable [](start = 37, length = 14)

How does this handle properties that are overridden or hidden (more than one symbol in the lookup result)? This does not correspond to how expressions are bound. #Closed

@gafter
Copy link
Member

gafter commented Apr 29, 2020

Finished reviewing (Iteration 6). I think there are four active comments from me. #Resolved

@agocke
Copy link
Member Author

agocke commented Apr 29, 2020

@gafter Thanks, updated. Regarding the lookup that will be adjusted soon in PRs unifying init-only and generating record Clone, so I've added prototype comments so I can include that in later PRs.

Copy link
Member

@gafter gafter left a comment

Choose a reason for hiding this comment

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

:shipit:

@agocke agocke merged commit e40e8f0 into dotnet:features/records May 1, 2020
@agocke agocke deleted the with-binding branch May 1, 2020 17:39
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