Skip to content

Inconsistency of in inlined implicits in scope #16372

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
nicolasstucki opened this issue Nov 18, 2022 · 3 comments
Open

Inconsistency of in inlined implicits in scope #16372

nicolasstucki opened this issue Nov 18, 2022 · 3 comments

Comments

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Nov 18, 2022

Compiler version

3.2.1, a1729b0

Minimized code

inline def f()(using Int): Int =
  compiletime.summonInline[Int]
inline def g(): Int = {
  given Int = 10
  compiletime.summonInline[Int]
}
def test =
  f()
  g()

Output

-- Error: tests/pos/i16372.scala:9:5 -----------------------------------
9 |  f()
  |     ^
  |     No given instance of type Int was found for parameter x$1 of method f

Expectation

Both examples should find the implicit Int. I expect the binding for the argument of f to be implicitly available.

Larger example
inline def f()(using Int): Int = compiletime.summonInline[Int]
inline def g(): Int = {
  given Int = 10
  compiletime.summonInline[Int]
}
inline def a(): Int = compiletime.summonInline[Int]
inline def h(): Int = {
  given Int = 10
  a()
}
inline def i(using Int): Int = a()
def test =
  f()
  g()
  h()
  i()
@nicolasstucki
Copy link
Contributor Author

There is also the question if the following should work (in #16160):

object O:
  given Int = 0
inline def f(): Int =
  import O._
  compiletime.summonInline[Int]
def test = f()

@jchyb
Copy link
Contributor

jchyb commented Nov 18, 2022

I may be mistaken, but I believe it is not that the summonInline from an inlined f() is not able to to find the given Int (supplied here via using Int), but that the using Int in f() (even before inlining) could not find a given to begin with.

With that said, I played with the example a little bit and I would perhaps expect this one to compile:

inline def f(): Int =
  compiletime.summonInline[Int]
inline def g(): Int = {
  given Int = 10
  compiletime.summonInline[Int]
}
def test =
  g()
  f()

as if it was inlined to

def test = 
  given Int = 10
  compiletime.summonInline[Int]
  compiletime.summonInline[Int]

Though maybe it is good that it does not. Is this what you meant?

@nicolasstucki
Copy link
Contributor Author

nicolasstucki commented Nov 18, 2022

This last example would be expanded to

def test = 
  {
    given Int = 10
    compiletime.summonInline[Int]
  }
  compiletime.summonInline[Int]

and that is why the given of g is not in scope for f.

@Kordyjan Kordyjan added this to the Future versions milestone Dec 12, 2022
@Decel Decel self-assigned this Nov 8, 2023
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

4 participants