Skip to content

Fix #7987: Use normal typer when expanding a macro #8117

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
Jan 29, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dotty.tools.dotc.tastyreflect
import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core._
import dotty.tools.dotc.core.Contexts._
import dotty.tools.dotc.typer.Typer
import dotty.tools.dotc.util.{Property, SourcePosition, Spans}

object MacroExpansion {
Expand All @@ -13,6 +14,6 @@ object MacroExpansion {
ctx.property(MacroExpansionPosition)

def context(inlinedFrom: tpd.Tree)(implicit ctx: Context): Context =
ctx.fresh.setProperty(MacroExpansionPosition, SourcePosition(inlinedFrom.source, inlinedFrom.span)).withSource(inlinedFrom.source)
ctx.fresh.setProperty(MacroExpansionPosition, SourcePosition(inlinedFrom.source, inlinedFrom.span)).setTypeAssigner(new Typer).withSource(inlinedFrom.source)
}

12 changes: 12 additions & 0 deletions tests/run-macros/i7987.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
scala.deriving.Mirror {
type MirroredType >: scala.Some[scala.Int] <: scala.Some[scala.Int]
type MirroredMonoType >: scala.Some[scala.Int] <: scala.Some[scala.Int]
type MirroredElemTypes >: scala.Nothing <: scala.Tuple
} & scala.deriving.Mirror.Product {
type MirroredMonoType >: scala.Some[scala.Int] <: scala.Some[scala.Int]
type MirroredType >: scala.Some[scala.Int] <: scala.Some[scala.Int]
type MirroredLabel >: "Some" <: "Some"
} {
type MirroredElemTypes >: scala.*:[scala.Int, scala.Unit] <: scala.*:[scala.Int, scala.Unit]
type MirroredElemLabels >: scala.*:["value", scala.Unit] <: scala.*:["value", scala.Unit]
}
12 changes: 12 additions & 0 deletions tests/run-macros/i7987/Macros_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import scala.quoted._
import scala.deriving._
import scala.quoted.matching._

object Macros {
inline def m(): String = ${ macroImpl() }

def macroImpl[T]()(given qctx: QuoteContext): Expr[String] = {
summonExpr[Mirror.Of[Some[Int]]] match
case Some('{ $_ : $t }) => Expr(t.show)
}
}
3 changes: 3 additions & 0 deletions tests/run-macros/i7987/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@main def Test() = {
println(Macros.m())
}