-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use canonical underlying type reference #10110
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,18 +16,18 @@ abstract class Test { | |||||
import t.given | ||||||
println(summon[Type[t.T]].show) | ||||||
// val r = '{Option.empty[t.T]} // access to value t from wrong staging level | ||||||
val r2 = '{Option.empty[${t.T}]} // works | ||||||
val r2 = '{Option.empty[t.T.Underlying]} // works | ||||||
} | ||||||
|
||||||
{ | ||||||
val r1 = '{Option.empty[${T}]} // works | ||||||
val r2 = '{Option.empty[List[${T}]]} // works | ||||||
val r3 = '{summon[Type[${T}]]} // error: is not stable | ||||||
val r4 = '{summon[${T} <:< Any]} // error: is not stable | ||||||
val r1 = '{Option.empty[T.Underlying]} // works | ||||||
val r2 = '{Option.empty[List[T.Underlying]]} // works | ||||||
val r3 = '{summon[Type[T.Underlying]]} // error: is not stable | ||||||
val r4 = '{summon[T.Underlying <:< Any]} // error: is not stable | ||||||
} | ||||||
|
||||||
{ | ||||||
val s = '{Option.empty[${T}]} // works | ||||||
val s = '{Option.empty[T.Underlying]} // works | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is equivalent but should not be changed to keep testing the same thing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, the second commit found the bug because I kept it as |
||||||
val r = '{identity($s)} // works | ||||||
val r2 = '{identity(${s: Expr[Option[T]]})} // error // error : is not stable | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import scala.quoted._ | ||
object Macro { | ||
inline def ff[T](x: T): T = ${ impl('x) } | ||
def impl[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{ $x: $t } | ||
def impl[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{ $x: T } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ import scala.quoted._ | |
|
||
object Test { | ||
def loop[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{ | ||
val y: $t = $x; | ||
${loop[$t]( // error | ||
val y: t.Underlying = $x; | ||
nicolasstucki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
${loop[t.Underlying]( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was actually crashing with an assertion failure at This also happens on master. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not open an issue as the fix was straightforward.
nicolasstucki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'y | ||
)} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
def typed[A](using t: quoted.Type[A], qctx: quoted.QuoteContext): Unit = { | ||
import qctx.reflect._ | ||
'{ | ||
type T = $t | ||
type T = A | ||
${'{???}.cast[T]} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little surprising that
List[T.Underlying]
works butsummon[Type[T.Underlying]]]
is an error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one was subtle.
The issue is that
given Type[T] = getT
is not stable. This is where I usually writegiven getT.type = getT
to not lose the path in the given.The other cases happen to work because we only referred to
T.Underlying
and never needed to head some type. This is the expected behavior.