-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Splice accessing path-dependent type with parameter crashes the compiler #16615
Labels
area:metaprogramming:quotes
Issues related to quotes and splices
area:pickling
itype:bug
itype:crash
Milestone
Comments
jodersky
added
itype:bug
itype:crash
stat:needs triage
Every issue needs to have an "area" and "itype" label
labels
Jan 4, 2023
prolativ
added
area:metaprogramming:quotes
Issues related to quotes and splices
area:pickling
and removed
stat:needs triage
Every issue needs to have an "area" and "itype" label
labels
Jan 5, 2023
Minimizedimport scala.quoted.*
trait Api:
type Reader[E]
def bugImpl[T: Type](using Quotes) =
'{
val p: Api = ???
${
Type.of[p.Reader[T]]
Expr(1)
}
} |
After the def bugImpl[T >: Nothing <: Any](implicit evidence$1: quoted.Type[T],
x$1: quoted.Quotes): quoted.Expr[Int] =
'{
{
val p: Api = ???
{{{ 0 | Int | p.Reader[evidence$1$_$1] |
{
def $anonfun(Type$1: scala.quoted.Type[p.Reader[evidence$1$_$1]])
: (quoted.Quotes) ?=> quoted.Expr[Int] =
{
def $anonfun(using evidence$2: quoted.Quotes):
quoted.Expr[Int] =
{
Type$1
quoted.Expr.apply[Int](1)(quoted.ToExpr.IntToExpr[Int])(
evidence$2)
}
closure($anonfun)
}
closure($anonfun:
scala.quoted.Type[p.Reader[evidence$1$_$1]] => (quoted.Quotes)
?=> quoted.Expr[Int]
)
}
}}}
}
}.apply(x$1) Having Instead, we should probably have def bugImpl[T >: Nothing <: Any](implicit evidence$1: quoted.Type[T],
x$1: quoted.Quotes): quoted.Expr[Int] =
'{
{
val p: Api = ???
{{{ 0 | Int | p.Reader |
{
def $anonfun(Type$1: scala.quoted.Type[p.Reader])
: (quoted.Quotes) ?=> quoted.Expr[Int] =
{
def $anonfun(using evidence$2: quoted.Quotes):
quoted.Expr[Int] =
{
quoted.Type.of[{
@SplicedType type evidence$1$_$1 = [[[ 0 | evidence$1.Underlying | | evidence$1 ]]]
@SplicedType type evidence$1$_$2 = [[[ 1 | Type$1.Underlying | | Type$1 ]]]
evidence$1$_$2[evidence$1$_$1]
}
quoted.Expr.apply[Int](1)(quoted.ToExpr.IntToExpr[Int])(
evidence$2)
}
closure($anonfun)
}
closure($anonfun:
scala.quoted.Type[p.Reader] => (quoted.Quotes)
?=> quoted.Expr[Int]
)
}
}}}
}
}.apply(x$1) |
nicolasstucki
added a commit
that referenced
this issue
Feb 9, 2023
Fixes #16615 Previously it was assumed that the type in Type.of could be captured as a whole, which meant that path dependent types for which a separate @SplicedType hole definitions were included in a block, would end up with missing references. Now when find a block in Type.of, we try to analise all parts of the type separately, adding additional hole definitions to the block as necessary. For types that can be captured as a whole (those which did not have a block generated previously, meaning they do not include any @SplicedType hole definitions), old method is used. In essence, ended up replicating the trees proposed in the original issue thread, which were incredibly helpful.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area:metaprogramming:quotes
Issues related to quotes and splices
area:pickling
itype:bug
itype:crash
Compiler version
master branch 3.3.0-RC1-bin-SNAPSHOT-nonbootstrapped-git-263eada
and also on latest official release, 3.2.1
Minimized code
Output (click arrow to expand)
Compile with
-Xcheck-macros -Ycheck:all
Expectation
I would think that both path-dependent and non-dependent types can be accessed the same way within splices.
The text was updated successfully, but these errors were encountered: