Skip to content

Getting undefined errors when using inline methods with opaque types #12914

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

Closed
ntnj opened this issue Jun 23, 2021 · 0 comments · Fixed by #12922
Closed

Getting undefined errors when using inline methods with opaque types #12914

ntnj opened this issue Jun 23, 2021 · 0 comments · Fixed by #12922
Milestone

Comments

@ntnj
Copy link

ntnj commented Jun 23, 2021

From https://contributors.scala-lang.org/t/allow-setters-with-multiple-arguments/5143/6

Compiler version

3.0.2-RC1-bin-20210621-4aa7f90-NIGHTLY
Scastie: https://scastie.scala-lang.org/LojQGNQeSvGLstjbzwaKBw

Minimized code

object opq:
  opaque type Str = java.lang.String
  object Str:
    def apply(s: String): Str = s
  inline def lower(s: Str): String = s.toLowerCase
    //error: undefined: a.toLowerCase # -1: TermRef(TermRef(NoPrefix,val a),toLowerCase) at inlining
  extension (s: Str)
    inline def upper: String = s.toUpperCase
    //error: undefined: a.toUpperCase # -1: TermRef(TermRef(NoPrefix,val a),toUpperCase) at inlining

@main def main =
  import opq.*
  val a: Str = Str("aSd")
  println(a.upper)
  println(opq.lower(a))

Output

Doesn't compile

Expectation

ASD
asd

@ntnj ntnj added the itype:bug label Jun 23, 2021
odersky added a commit to dotty-staging/dotty that referenced this issue Jun 24, 2021
An argument of an inlined call might have a type that refers to opaque
types in the inlined method's scope. In that case, we need to cast those
arguments to types where the opaque references are replaced by proxies,
so that the opaque aliases are visible when accessing the argument.

Fixes scala#12914
@Kordyjan Kordyjan added this to the 3.0.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants