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

Inlining issue for named tuples hidden behind opaque types #22324

Open
hamzaremmal opened this issue Jan 8, 2025 · 1 comment · May be fixed by #22340
Open

Inlining issue for named tuples hidden behind opaque types #22324

hamzaremmal opened this issue Jan 8, 2025 · 1 comment · May be fixed by #22340
Assignees
Labels

Comments

@hamzaremmal
Copy link
Member

hamzaremmal commented Jan 8, 2025

Compiler version

3.6.2

Minimized code

//> using scala 3.6.2
//> using options -experimental

import scala.language.experimental.namedTuples

opaque type System = (wires: Any)

extension (system: System)
  inline def foo = system.wires
end extension

val simulation: System = ???
val _ = simulation.foo

Output

-- Error: solution.scala:12:19 -------------------------------------------------
 12 |val _ = simulation.foo
    |        ^^^^^^^^^^^^^^
    |undefined: tup.productElement # -1: TermRef(TermRef(NoPrefix,val tup),productElement) at inlining
    |---------------------------------------------------------------------------
    |Inline stack trace
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from NamedTuple.scala:144
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from NamedTuple.scala:144
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from NamedTuple.scala:144
  9 |  inline def foo = system.wires
    |                   ^^^^^^^^^^^^
     ---------------------------------------------------------------------------
1 error found

Expectation

Compiles without any issue

Notes

  • The soft keyword opaque in System is important to reproduce the issue
  • The soft keyword inline in foo is important to reproduce the issue
@EugeneFlesselle
Copy link
Contributor

Potentially related to #14653, #20427

@hamzaremmal hamzaremmal changed the title Inlining issue for named tuples hidden behing opaque types Inlining issue for named tuples hidden behind opaque types Jan 8, 2025
EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Jan 10, 2025
….apply`

We previously needed to handle the case where the result of `toTuple` was an
`EmptyTuple` separately from the rest, since `apply` used to be only defined for
`NonEmptyTuple`s. This was changed in scala#21291, making the inline match in
`NamedTupleDecomposition.apply` no longer necessary.

The underlying issue with the proxies introduced to handle opaque types with
inline defs is likely still present. Nevertheless, it is probably best to fix
this specific instance of the problem with NamedTuples as soon as possible.

Fixes scala#22324
EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Jan 10, 2025
We previously needed to handle the case where the result of `toTuple` was an
`EmptyTuple` separately from the rest, since `apply` used to be only defined for
`NonEmptyTuple`s. This was changed in scala#21291, making the inline match in
`NamedTupleDecomposition.apply` no longer necessary.

The underlying issue with the proxies introduced to handle opaque types with
inline defs is likely still present. Nevertheless, it is probably best to fix
this specific instance of the problem with NamedTuples as soon as possible.

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

Successfully merging a pull request may close this issue.

3 participants