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

Cannot select from named tuple literal #21413

Closed
prolativ opened this issue Aug 22, 2024 · 3 comments · Fixed by #21680
Closed

Cannot select from named tuple literal #21413

prolativ opened this issue Aug 22, 2024 · 3 comments · Fixed by #21680
Assignees
Labels
area:experimental:named-tuples Issues tied to the named tuples feature. itype:bug
Milestone

Comments

@prolativ
Copy link
Contributor

Compiler version

3.5.0
3.6.0-RC1-bin-20240821-a2c53a1-NIGHTLY

Minimized code

import scala.language.experimental.namedTuples

val x = (aaa = 1).aaa

Output

-- [E007] Type Mismatch Error: /tmp/NamedTuple.scala:3:18 ----------------------
  3 |val x = (aaa = 1).aaa
    |        ^^^^^^^^^^^^^
    |        Found:    Tuple1[Int]
    |        Required: (x$proxy2 : Tuple1[Int])
    |---------------------------------------------------------------------------
    |Inline stack trace
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from NamedTuple.scala:40
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from NamedTuple.scala:40
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from NamedTuple.scala:40
     ---------------------------------------------------------------------------
    |
    | longer explanation available when compiling with `-explain`

Expectation

This should compile successfully

@prolativ prolativ added itype:bug area:experimental:named-tuples Issues tied to the named tuples feature. labels Aug 22, 2024
@KacperFKorban KacperFKorban self-assigned this Aug 23, 2024
@KacperFKorban
Copy link
Member

Looks like changing the inline def here into a transparent inline def fixes the problem, but I'm not sure if that is desired.

inline def apply(n: Int): Tuple.Elem[V, n.type] =

@aherlihy @EugeneFlesselle do you see any problems with making that change?

@soronpo
Copy link
Contributor

soronpo commented Sep 20, 2024

Also, it appears there is a reporting issue here.

    |This location contains code that was inlined from NamedTuple.scala:40
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from NamedTuple.scala:40
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from NamedTuple.scala:40
     ---------------------------------------------------------------------------

This repetition provides no additional information and seems wrong to me.

@odersky
Copy link
Contributor

odersky commented Oct 3, 2024

It looks like an Inliner bug. Basically, the inliner inlines a val x$proxy as x$proxy2: Tuple1[Int] and then tries
to adapt this to the expected type x$proxy2.type.

Fixed by #21680

@odersky odersky linked a pull request Oct 3, 2024 that will close this issue
@WojciechMazur WojciechMazur added this to the 3.6.0 milestone Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:experimental:named-tuples Issues tied to the named tuples feature. itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants