Skip to content
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

Fix splice type variable pattern detection #17048

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ trait QuotesAndSplices {
val pat1 = if (patType eq patType1) pat else pat.withType(patType1)
patBuf += pat1
}
case Select(pat, _) if tree.symbol.isTypeSplice =>
case Select(pat: Bind, _) if tree.symbol.isTypeSplice =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • How are Select where the prefix is not a Bind handled?
  • There are other cases which involve pat like case Apply(fn, pat :: Nil), should those be pat: Bind too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are Select where the prefix is not a Bind handled?

Those just get the default super.transform(tree). The splitter only needs to extract the bindings of the pattern. For types, these are the type variable inline definitions. If there is a t.Underlying that is not a pattern we assume that it is an explicit splice into the pattern. In case, t is not identified as a type variable because t is part of the path of the type.

There are other cases which involve pat like case Apply(fn, pat :: Nil), should those be pat: Bind too?

These are expression splices ${...} in the pattern. There we can have an arbitrary pattern such as ${x} or ${Expr(x)}. Unlike with types, we do not have a notation or notion of inserting an expression is a quoted pattern.

val sym = tree.tpe.dealias.typeSymbol
if sym.exists then
val tdef = TypeDef(sym.asType).withSpan(sym.span)
Expand Down
7 changes: 7 additions & 0 deletions tests/pos-macros/i17039.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted.*

def macroImpl(using Quotes) =
val t = summon[Type[Int]]
Type.of[Int] match
case '[t.Underlying] => '{true}
case _ => '{false}