Skip to content
Open
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
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ object Contexts {

/** Is current phase after TyperPhase? */
final def isAfterTyper = base.isAfterTyper(phase)
final def isAfterInlining = base.isAfterInlining(phase)
final def isTyper = base.isTyper(phase)

/** Is this a context for the members of a class definition? */
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ object Phases {
}

final def isAfterTyper(phase: Phase): Boolean = phase.id > typerPhase.id
final def isAfterInlining(phase: Phase): Boolean =
inliningPhase != NoPhase && phase.id > inliningPhase.id
final def isTyper(phase: Phase): Boolean = phase.id == typerPhase.id
}

Expand Down Expand Up @@ -375,6 +377,7 @@ object Phases {
val doCheckJava = skipIfJava && !isAfterLastJavaPhase
for unit <- units do ctx.profiler.onUnit(this, unit):
given unitCtx: Context = runCtx.fresh.setPhase(this.start).setCompilationUnit(unit).withRootImports
val previousTyperState = unitCtx.typerState.snapshot()
if ctx.run.enterUnit(unit) then
try
if doCheckJava && unit.typedAsJava then
Expand All @@ -384,6 +387,7 @@ object Phases {
buf += unitCtx.compilationUnit
catch
case _: CompilationUnit.SuspendException => // this unit will be run again in `Run#compileSuspendedUnits`
unitCtx.typerState.resetTo(previousTyperState)
case ex: Throwable if !ctx.run.enrichedErrorMessage =>
println(ctx.run.enrichErrorMessage(s"unhandled exception while running $phaseName on $unit"))
throw ex
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2974,7 +2974,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
typedExpr(_, tpt1.tpe.widenExpr)
val vdef1 = assignType(cpy.ValDef(vdef)(name, tpt1, rhs1), sym)
postProcessInfo(vdef1, sym)
vdef1.setDefTree
if (!ctx.isAfterInlining) vdef1.setDefTree

migrate(ImplicitToGiven.valDef(vdef1))

Expand Down Expand Up @@ -3097,7 +3097,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
if (!sym.isOneOf(Synthetic | InlineProxy | Param) && sym.info.finalResultType.isRepeatedParam)
report.error(em"Cannot return repeated parameter type ${sym.info.finalResultType}", sym.srcPos)
mdef.ensureHasSym(sym)
mdef.setDefTree
if (!ctx.isAfterInlining) mdef.setDefTree
else mdef

def typedTypeDef(tdef: untpd.TypeDef, sym: Symbol)(using Context): Tree = ctx.profiler.onTypedDef(sym) {
val TypeDef(name, rhs) = tdef
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-macros/i22584/Macro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object Macros {
}
}

val expected = "List(DefDef(boolean,List(List()),TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Boolean)],Select(This(Ident(MyClass1)),boolean)), DefDef(finalVal,List(List()),TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),class String)],Select(This(Ident(MyClass1)),finalVal)), DefDef(int,List(List()),TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Int)],Select(This(Ident(MyClass1)),int)), DefDef(string,List(List()),TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),class String)],Select(This(Ident(MyClass1)),string)))"
val expected = "List(ValDef(boolean,TypeTree[TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Boolean)],EmptyTree), ValDef(finalVal,Ident(String),Literal(Constant(result))), ValDef(int,TypeTree[TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Int)],EmptyTree), ValDef(string,TypeTree[TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class scala)),object Predef),type String)],EmptyTree))"
assert(caseFieldValOrDefDefs.toString == expected)

'{ () }
Expand Down
12 changes: 12 additions & 0 deletions tests/pos/i21176-a/Macro.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//> using options -Wsafe-init
import scala.quoted.*

class Macro:
def tuple[T](name: String): (String, List[T]) = (name, List[T]())
inline def nameTuple[T]: (String, List[T]) = tuple(Macro.named)

object Macro:
def namedMacro(using q: Quotes): Expr[String] =
Expr("test")

inline def named: String = ${Macro.namedMacro}
7 changes: 7 additions & 0 deletions tests/pos/i21176-a/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//> using options -Wsafe-init
class Test extends Macro:
val abc = nameTuple[Int]

@main
def run(): Unit =
println(new Test().abc)
9 changes: 9 additions & 0 deletions tests/pos/i21176-b/Macro.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import scala.quoted.*

class Macro:
inline def nameTuple[NameTuple_T]: (String, List[NameTuple_T]) = Macro.tuple[NameTuple_T](Macro.named)

object Macro:
def namedMacro(using q: Quotes): Expr[String] = Expr("test")
inline def named: String = ${Macro.namedMacro}
def tuple[Tuple_T](name: String): (String, List[Tuple_T]) = (name, List.empty[Tuple_T])
2 changes: 2 additions & 0 deletions tests/pos/i21176-b/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Test extends Macro:
val abc = nameTuple[Int]
Loading