Skip to content

Propagate EffectiveScope to parameters of anonymous delegate types.#63787

Merged
AlekseyTs merged 2 commits intodotnet:mainfrom
AlekseyTs:Issue63565
Sep 12, 2022
Merged

Propagate EffectiveScope to parameters of anonymous delegate types.#63787
AlekseyTs merged 2 commits intodotnet:mainfrom
AlekseyTs:Issue63565

Conversation

@AlekseyTs
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs commented Sep 3, 2022

Fixes #63565.
Closes #63078.

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@cston, @RikkiGibson, @dotnet/roslyn-compiler Please review

/// <summary>
/// The declared scope. From source, this is from the <c>scope</c> keyword only.
/// </summary>
internal DeclarationScope DeclaredScope => _scope;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

DeclaredScope

It looks like this fixes #63078.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It looks like this fixes #63078.

Thanks. I'll mark the issue as closed by this PR.

allowThis: false,
addRefReadOnlyModifier: addRefReadOnlyModifier,
diagnostics: diagnostics);
diagnostics: diagnostics).Cast<SourceParameterSymbol, ParameterSymbol>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

.Cast<SourceParameterSymbol, ParameterSymbol>()

We're casting to ParameterSymbol in many callers of MakeParameters(). Where are we using the change to SourceParameterSymbol, and would it make sense to cast that case to SourceParameterSymbol instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We're casting to ParameterSymbol in many callers of MakeParameters(). Where are we using the change to SourceParameterSymbol, and would it make sense to cast that case to SourceParameterSymbol instead?

Is there a specific concern? This is a safe in-place cast. I intentionally changed return type to a more specific type in order to ensure that assumptions made in ParameterHelpers.ReportParameterErrors are justified.

}
}
";
var comp = CreateCompilation(new[] { source, UnscopedRefAttributeDefinition }, targetFramework: TargetFramework.NetCoreApp, options: TestOptions.ReleaseDll);
Copy link
Copy Markdown
Contributor

@cston cston Sep 7, 2022

Choose a reason for hiding this comment

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

targetFramework: TargetFramework.NetCoreApp

Minor: Is targetFramework needed in these tests?

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@RikkiGibson, @dotnet/roslyn-compiler For the second review.

@RikkiGibson RikkiGibson self-assigned this Sep 7, 2022
@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@RikkiGibson, @dotnet/roslyn-compiler For the second review.

parameterRefKinds,
refKind: default,
returnType: default);
lambdaSymbol = createLambdaSymbol();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems strange that we will sometimes create a lambda symbol which gets thrown away in order to produce information like the inferred return type or effective scope of parameters, and then later on presumably produce a "final" lambda symbol. Is this a sign that there's some design debt here which could be addressed in the future?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is this a sign that there's some design debt here which could be addressed in the future?

I do not think so. As long as this doesn't become a source of performance problem, that isn't something that I would worry about.

@AlekseyTs AlekseyTs merged commit d960d03 into dotnet:main Sep 12, 2022
@ghost ghost added this to the Next milestone Sep 12, 2022
@Cosifne Cosifne modified the milestones: Next, 17.4 P3 Sep 26, 2022
@jcouv
Copy link
Copy Markdown
Member

jcouv commented Oct 11, 2022

@AlekseyTs I can't find this behavior described in the spec. Should we document it? Did we confirm with LDM this is desirable?

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

I can't find this behavior described in the spec. Should we document it? Did we confirm with LDM this is desirable?

My understanding is that that we were propagating something already that didn't make sense in many scenarios. Triage determined that the behavior was not desirable and was classified as a bug. At this point I do not remember whether this behavior or the previous behavior was explicitly documented in the spec. If you believe we should have a different behavior, feel free to open a bug or bring this for LDM discussion.

@jcouv
Copy link
Copy Markdown
Member

jcouv commented Oct 12, 2022

Discussed with @cston and filed #64670 for follow-up (spec needs updating)

jjonescz added a commit to jjonescz/roslyn that referenced this pull request Oct 26, 2022
jjonescz added a commit that referenced this pull request Nov 1, 2022
…4966)

* Pass information to delegate inference through method symbol

* Fix `DefaultParameterValue` test

* Update caller info attribute tests

* Enable lambda nullable reference types test

* Parametrize IL snapshots

* Test caller info attrs without default values

* Fix merge of #63787

* Simplify by using a list pattern

* Avoid creating a second `LambdaSymbol`

* Add parameter scopes override

* Keep comments at lines with expected diagnostics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Implicitly typed lambdas with [UnscopedRef] don't match their own anonymous delegate types Remove or reduce use of ParameterSymbol.DeclaredScope

5 participants