Skip to content

Commit

Permalink
Remove the -rewrite option for typechecks methods in Quotes (#21547)
Browse files Browse the repository at this point in the history
Fixes #21415

This is somewhat related to #21185, but I think it's better to merge
this one separately first since it's an easy backport, which might not
be the case with the other PR (since we are technically changing the
semantics there)
  • Loading branch information
hamzaremmal authored Sep 13, 2024
2 parents d2bb85d + 6f21759 commit 61adf81
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/config/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/inlines/Inlines.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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, _))
Expand Down
3 changes: 3 additions & 0 deletions compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,6 @@ parsercombinators-new-syntax.scala
hylolib-deferred-given
hylolib-cb
hylolib

# typecheckErrors method unpickling
i21415.scala
4 changes: 3 additions & 1 deletion compiler/test/dotc/run-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,3 +46,6 @@ trait-static-forwarder
i17255
named-tuples-strawman-2.scala

# typecheckErrors method unpickling
typeCheckErrors.scala

8 changes: 8 additions & 0 deletions tests/pos/i21415.scala
Original file line number Diff line number Diff line change
@@ -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 _)")

0 comments on commit 61adf81

Please sign in to comment.