Open soronpo opened 2 years ago
The issue is that when we type the top level splice we get the wrong implicit for Type[T]
.
inline given foo[T <: Foo]: T = ${ fooMacro[T] }
is typed as
inline given foo[T <: Foo]: T = ${ quotes ?=> fooMacro[T](using quotes, foo[Foo & Type[T]]) }
instead of
inline given foo[T <: Foo]: T = ${ quotes ?=> fooMacro[T](using quotes, Type.of[T]) }
- inline given foo[T <: Foo]: T = ${ fooMacro[T] }
+ inline given foo[T <: Foo]: T = ${ quotes ?=> fooMacro[T](using quotes, Type.of[T]) }
It seems that in general inline given foo[T <: Foo]: T
can be used to create any implicit.
trait Foo
object Foo:
inline given foo[T <: Foo]: T = summon[Option[T]]
-- Warning: tests/pos-macros/i15685.scala:3:24 ---------------------------------
3 | inline given foo[T ]: T = summon[Option[T]]
| ^^^^^^^^^^^^^^^^^^^^^
| Infinite loop in function body
| summon[Option[T]](Foo.foo[Nothing]):T
If we change the example from
inline given
toinline def
no errors occur.Compiler version
v3.2.0-RC2
Minimized code
https://scastie.scala-lang.org/QTG7yUwtRASOb0vRiGDxog
Output
Expectation
No error.