Skip to content

Commit c5adae8

Browse files
committed
Fix #7987: Use normal typer when expanding a macro
1 parent c4a3de4 commit c5adae8

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/MacroExpansion.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dotty.tools.dotc.tastyreflect
33
import dotty.tools.dotc.ast.tpd
44
import dotty.tools.dotc.core._
55
import dotty.tools.dotc.core.Contexts._
6+
import dotty.tools.dotc.typer.Typer
67
import dotty.tools.dotc.util.{Property, SourcePosition, Spans}
78

89
object MacroExpansion {
@@ -13,6 +14,6 @@ object MacroExpansion {
1314
ctx.property(MacroExpansionPosition)
1415

1516
def context(inlinedFrom: tpd.Tree)(implicit ctx: Context): Context =
16-
ctx.fresh.setProperty(MacroExpansionPosition, SourcePosition(inlinedFrom.source, inlinedFrom.span)).withSource(inlinedFrom.source)
17+
ctx.fresh.setProperty(MacroExpansionPosition, SourcePosition(inlinedFrom.source, inlinedFrom.span)).setTypeAssigner(new Typer).withSource(inlinedFrom.source)
1718
}
1819

tests/run-macros/i7987.check

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
scala.deriving.Mirror {
2+
type MirroredType >: scala.Some[scala.Int] <: scala.Some[scala.Int]
3+
type MirroredMonoType >: scala.Some[scala.Int] <: scala.Some[scala.Int]
4+
type MirroredElemTypes >: scala.Nothing <: scala.Tuple
5+
} & scala.deriving.Mirror.Product {
6+
type MirroredMonoType >: scala.Some[scala.Int] <: scala.Some[scala.Int]
7+
type MirroredType >: scala.Some[scala.Int] <: scala.Some[scala.Int]
8+
type MirroredLabel >: "Some" <: "Some"
9+
} {
10+
type MirroredElemTypes >: scala.*:[scala.Int, scala.Unit] <: scala.*:[scala.Int, scala.Unit]
11+
type MirroredElemLabels >: scala.*:["value", scala.Unit] <: scala.*:["value", scala.Unit]
12+
}

tests/run-macros/i7987/Macros_1.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.quoted._
2+
import scala.deriving._
3+
import scala.quoted.matching._
4+
5+
object Macros {
6+
inline def m(): String = ${ macroImpl() }
7+
8+
def macroImpl[T]()(given qctx: QuoteContext): Expr[String] = {
9+
summonExpr[Mirror.Of[Some[Int]]] match
10+
case Some('{ $_ : $t }) => Expr(t.show)
11+
}
12+
}

tests/run-macros/i7987/Test_2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@main def Test() = {
2+
println(Macros.m())
3+
}

0 commit comments

Comments
 (0)