Skip to content

inline and opaque types, illegal given resolution #22370

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

Open
road21 opened this issue Jan 15, 2025 · 1 comment
Open

inline and opaque types, illegal given resolution #22370

road21 opened this issue Jan 15, 2025 · 1 comment

Comments

@road21
Copy link
Contributor

road21 commented Jan 15, 2025

Compiler version

3.3.4, 3.6.2

Minimized code

import scala.compiletime.*

object module:
  opaque type X[x] = x
  object X:
    given X[Int] = 5
    inline def get[x] = summonInline[X[x]]
  end X  
  //summon[X[Int]] // doesn't compile and this is probably ok
end module

import module.X
summon[X[Int]]
X.get[Int] // doesn't compile and this is a bug

https://scastie.scala-lang.org/road21/RKS79oblTUG87DzuRlPkAg/23

Output

Compiler error:
No given instance of type module$_this.X[Int] was found

Expectation

No compiler error

I expect that inlining happens in-place and given should be found. If I move the get method to separate object It compiles (shown in scastie link).

@road21 road21 added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 15, 2025
@som-snytt
Copy link
Contributor

The expansion is

          {
            val $proxy1: module.type{type X[x] = x} =
              module.$asInstanceOf[module.type{type X[x] = x}]
            val module$_this: ($proxy1 : module.type{type X[x] = x}) = $proxy1
            (scala.compiletime.summonInline[module$_this.X[Int]]:
              module$_this.X[Int])
          }.$asInstanceOf[module.X[Int]]

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

No branches or pull requests

3 participants