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

Describe scoping rules for extension declaration type parameters and receiver parameter #9229

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

MadsTorgersen
Copy link
Contributor

Based on LDM feedback, these are revised scoping rules for extension declarations.

@MadsTorgersen MadsTorgersen requested a review from a team as a code owner March 17, 2025 20:09
@MadsTorgersen MadsTorgersen marked this pull request as draft March 17, 2025 20:12
@MadsTorgersen MadsTorgersen marked this pull request as ready for review March 17, 2025 20:23
@@ -50,6 +50,38 @@ receiver_parameter // add
Extension declarations shall only be declared in non-generic, non-nested static classes.
It is an error for a type to be named `extension`.

### Scoping rules

The type parameters and receiver parameter of an extension declaration are in scope within the body of the extension declaration. It is an error to refer to the receiver parameter from within a static member. It is an error for members to declare type parameters or parameters with the same name as a type parameter or receiver parameter of the extension declaration.
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 20, 2025

Choose a reason for hiding this comment

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

It is an error to refer to the receiver parameter from within a static member.

It is an error to refer to the receiver parameter from within a static member.

Consider relaxing this restriction for references inside nameof (nameof arguments). We do that for primary constructor parameters as well.

Copy link
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 9)

@@ -50,6 +50,38 @@ receiver_parameter // add
Extension declarations shall only be declared in non-generic, non-nested static classes.
It is an error for a type to be named `extension`.

### Scoping rules

The type parameters and receiver parameter of an extension declaration are in scope within the body of the extension declaration. It is an error to refer to the receiver parameter from within a static member. It is an error for members to declare type parameters or parameters with the same name as a type parameter or receiver parameter of the extension declaration.
Copy link
Contributor

Choose a reason for hiding this comment

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

It is an error for members to declare type parameters or parameters with the same name as a type parameter or receiver parameter of the extension declaration.

I think it is worth mentioning that the same goes for local variables and local function declared directly by members (not inside lamndas or local functions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants