Skip to content

Fix issue with certain synthetics missing in compiletime.typechecks #22978

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/CompilationUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ object CompilationUnit {
unit1
}

/** Create a compilation unit corresponding to an in-memory String.
/** Create a compilation unit corresponding to an in-memory String.
* Used for `compiletime.testing.typeChecks`.
*/
def apply(name: String, source: String)(using Context): CompilationUnit = {
def apply(name: String, source: String): CompilationUnit = {
val src = SourceFile.virtual(name = name, content = source, maybeIncomplete = false)
new CompilationUnit(src, null)
}
Expand Down
38 changes: 21 additions & 17 deletions compiler/src/dotty/tools/dotc/inlines/Inlines.scala
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ object Inlines:
case ConstantType(Constant(code: String)) =>
val unitName = "tasty-reflect"
val source2 = SourceFile.virtual(unitName, code)
def compilationUnits(untpdTree: untpd.Tree, tpdTree: Tree): List[CompilationUnit] =
val compilationUnit = CompilationUnit(unitName, code)
compilationUnit.tpdTree = tpdTree
compilationUnit.untpdTree = untpdTree
List(compilationUnit)
// We need a dummy owner, as the actual one does not have a computed denotation yet,
// but might be inspected in a transform phase, leading to cyclic errors
val dummyOwner = newSymbol(ctx.owner, "$dummySymbol$".toTermName, Private, defn.AnyType, NoSymbol)
Expand All @@ -407,31 +412,30 @@ object Inlines:
.withOwner(dummyOwner)

inContext(newContext) {
val tree2 = new Parser(source2).block()
if ctx.reporter.allErrors.nonEmpty then
def noErrors = ctx.reporter.allErrors.isEmpty
val untpdTree = new Parser(source2).block()
if !noErrors then
ctx.reporter.allErrors.map((ErrorKind.Parser, _))
else
val tree3 = ctx.typer.typed(tree2)
val tpdTree1 = ctx.typer.typed(untpdTree)
ctx.base.postTyperPhase match
case postTyper: PostTyper if ctx.reporter.allErrors.isEmpty =>
val tree4 = atPhase(postTyper) { postTyper.newTransformer.transform(tree3) }
case postTyper: PostTyper if noErrors =>
val tpdTree2 =
atPhase(postTyper) { postTyper.runOn(compilationUnits(untpdTree, tpdTree1)).head.tpdTree }
ctx.base.setRootTreePhase match
case setRootTree =>
val tree5 =
val compilationUnit = CompilationUnit(unitName, code)
compilationUnit.tpdTree = tree4
compilationUnit.untpdTree = tree2
var units = List(compilationUnit)
atPhase(setRootTree)(setRootTree.runOn(units).head.tpdTree)
case setRootTree if noErrors => // might be noPhase, if -Yretain-trees is not used
val tpdTree3 =
atPhase(setRootTree)(setRootTree.runOn(compilationUnits(untpdTree, tpdTree2)).head.tpdTree)
ctx.base.inliningPhase match
case inlining: Inlining if ctx.reporter.allErrors.isEmpty =>
val tree6 = atPhase(inlining) { inlining.newTransformer.transform(tree5) }
if ctx.reporter.allErrors.isEmpty && reconstructedTransformPhases.nonEmpty then
var transformTree = tree6
case inlining: Inlining if noErrors =>
val tpdTree4 = atPhase(inlining) { inlining.newTransformer.transform(tpdTree3) }
if noErrors && reconstructedTransformPhases.nonEmpty then
var transformTree = tpdTree4
for phase <- reconstructedTransformPhases do
if ctx.reporter.allErrors.isEmpty then
if noErrors then
transformTree = atPhase(phase.end + 1)(phase.transformUnit(transformTree))
case _ =>
case _ =>
case _ =>
ctx.reporter.allErrors.map((ErrorKind.Typer, _))
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotc/run-test-pickling.excludelist
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ named-tuples-strawman-2.scala
# typecheckErrors method unpickling
typeCheckErrors.scala
i18150.scala

i22968.scala
1 change: 1 addition & 0 deletions tests/run/i22968.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
List()
7 changes: 7 additions & 0 deletions tests/run/i22968.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.compiletime.testing.typeCheckErrors

object Test {
def main(args: Array[String]): Unit = {
println(typeCheckErrors("enum Foo { case A }"))
}
}
Loading