Skip to content

Conversation

aherlihy
Copy link
Contributor

Fixes #24021

untpd.Literal(Constant(nameIdx))),
pt)
if selName == nme.apply then
EmptyTree
Copy link
Contributor

@road21 road21 Oct 15, 2025

Choose a reason for hiding this comment

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

What is the behavior of the following code now:

val boo: NamedTuple.NamedTuple[("_2", "apply"), (Int, Int)] = (1, 2)
println(boo.apply)

I mean, that's too easy to bypass restrictions on named tuple field names. What error will be in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The validation doesn't apply to non-standard construction of named tuples (#23360). The compiler team decided that validation should only be applied to named tuples created with the spec (k:V) syntax. Either way of course it should not crash the compiler.

@odersky
Copy link
Contributor

odersky commented Oct 16, 2025

I think we can probably do a slightly different approach, in that we don't try to do member selection on a named tuple if that tuple defines the apply method. That would make the scheme water-tight even for tuples constructed by hand with NamedTuple(...). @aherlihy can you move your PR to dotty-staging, then I can add a commit with that tweak?

odersky added a commit to dotty-staging/dotty that referenced this pull request Oct 16, 2025
Similar to scala#24188, but we now disallow `apply` members at tuple selection
instead of tuple formation. This also works for hand-rolled
tuples built using `NamedTuple(...)`. And it constitutes the minimal fix
to avoid the recursion.
@aherlihy
Copy link
Contributor Author

Replaced by #24191

@aherlihy aherlihy closed this Oct 16, 2025
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.

Compiler crashes when named tuple with apply field is used

3 participants