diff --git a/compiler/src/dotty/tools/dotc/config/Settings.scala b/compiler/src/dotty/tools/dotc/config/Settings.scala index 7454682fba56..a5fc6a64aa45 100644 --- a/compiler/src/dotty/tools/dotc/config/Settings.scala +++ b/compiler/src/dotty/tools/dotc/config/Settings.scala @@ -47,6 +47,10 @@ object Settings: values(idx) = x changed.add(idx) this + + def reinitializedCopy(): SettingsState = + SettingsState(values.toSeq, changed.toSet) + end SettingsState case class ArgsSummary( diff --git a/compiler/src/dotty/tools/dotc/inlines/Inlines.scala b/compiler/src/dotty/tools/dotc/inlines/Inlines.scala index fffe87c3f57a..c1ab5f99d8d2 100644 --- a/compiler/src/dotty/tools/dotc/inlines/Inlines.scala +++ b/compiler/src/dotty/tools/dotc/inlines/Inlines.scala @@ -342,10 +342,13 @@ object Inlines: if Inlines.isInlineable(codeArg1.symbol) then stripTyped(Inlines.inlineCall(codeArg1)) else codeArg1 + // We should not be rewriting tested strings + val noRewriteSettings = ctx.settings.rewrite.updateIn(ctx.settingsState.reinitializedCopy(), None) + ConstFold(underlyingCodeArg).tpe.widenTermRefExpr match { case ConstantType(Constant(code: String)) => val source2 = SourceFile.virtual("tasty-reflect", code) - inContext(ctx.fresh.setNewTyperState().setTyper(new Typer(ctx.nestingLevel + 1)).setSource(source2)) { + inContext(ctx.fresh.setSettings(noRewriteSettings).setNewTyperState().setTyper(new Typer(ctx.nestingLevel + 1)).setSource(source2)) { val tree2 = new Parser(source2).block() if ctx.reporter.allErrors.nonEmpty then ctx.reporter.allErrors.map((ErrorKind.Parser, _)) diff --git a/compiler/test/dotc/pos-test-pickling.blacklist b/compiler/test/dotc/pos-test-pickling.blacklist index b68ac7fc3b6e..032b53150e49 100644 --- a/compiler/test/dotc/pos-test-pickling.blacklist +++ b/compiler/test/dotc/pos-test-pickling.blacklist @@ -135,3 +135,6 @@ parsercombinators-new-syntax.scala hylolib-deferred-given hylolib-cb hylolib + +# typecheckErrors method unpickling +i21415.scala diff --git a/compiler/test/dotc/run-test-pickling.blacklist b/compiler/test/dotc/run-test-pickling.blacklist index dacbc63bb520..31304e061bc7 100644 --- a/compiler/test/dotc/run-test-pickling.blacklist +++ b/compiler/test/dotc/run-test-pickling.blacklist @@ -27,7 +27,6 @@ tuple-zip.scala tuples1.scala tuples1a.scala tuples1b.scala -typeCheckErrors.scala typeclass-derivation-doc-example.scala typeclass-derivation1.scala typeclass-derivation2.scala @@ -47,3 +46,6 @@ trait-static-forwarder i17255 named-tuples-strawman-2.scala +# typecheckErrors method unpickling +typeCheckErrors.scala + diff --git a/tests/pos/i21415.scala b/tests/pos/i21415.scala new file mode 100644 index 000000000000..04afd512b535 --- /dev/null +++ b/tests/pos/i21415.scala @@ -0,0 +1,8 @@ +//> using options -rewrite -source:3.4-migration +import scala.compiletime.testing.typeCheckErrors + +def foo(arg: Int): Unit = ??? + +@main def Test = + typeCheckErrors("Seq.empty[Int].foreach(foo.apply _)") + typeCheckErrors("Seq.empty[Int].foreach(foo.apply _)")