Skip to content

Fix #7715: Fix Inlined.{isTerm,isType} and case with Inlined(Nil, ...) #7733

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

Merged
merged 1 commit into from
Dec 13, 2019
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: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ object Trees {
case class Inlined[-T >: Untyped] private[ast] (call: tpd.Tree, bindings: List[MemberDef[T]], expansion: Tree[T])(implicit @constructorOnly src: SourceFile)
extends Tree[T] {
type ThisTree[-T >: Untyped] = Inlined[T]
override def isTerm = expansion.isTerm
override def isType = expansion.isType
}

/** A type tree that represents an existing or inferred type */
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
transform(rhs)
case _ => tree
}
case Inlined(_, _, arg) => transform(arg)
case Inlined(_, Nil, arg) => transform(arg)
case Block(Nil, arg) => transform(arg)
case NamedArg(_, arg) => transform(arg)
case tree => super.transform(tree)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
def runtimeClass: Class[?] = classOf[Term]
override def unapply(x: Any): Option[Term] = x match
case _ if isInstanceOfUnapply.unapply(x).isDefined => None
case _: PatternTree => None
case _: tpd.PatternTree => None
case x: tpd.SeqLiteral => Some(x)
case x: Tree if x.isTerm => Some(x)
case x: tpd.Tree if x.isTerm => Some(x)
case _ => None
}

Expand Down
Empty file added tests/run-macros/i7715.check
Empty file.
6 changes: 6 additions & 0 deletions tests/run-macros/i7715/Macros_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.quoted.{ given, _ }

inline def mcr(e: => Any): Any = ${mcrImpl('e)}
def mcrImpl(e: Expr[Any])(given ctx: QuoteContext): Expr[Any] =
e match
case '{ $body } => body
2 changes: 2 additions & 0 deletions tests/run-macros/i7715/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
given Int = 5
@main def Test = assert(5 == mcr(summon[Int]))