Skip to content

Commit 61adf81

Browse files
authored
Remove the -rewrite option for typechecks methods in Quotes (#21547)
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)
2 parents d2bb85d + 6f21759 commit 61adf81

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

Diff for: compiler/src/dotty/tools/dotc/config/Settings.scala

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ object Settings:
4747
values(idx) = x
4848
changed.add(idx)
4949
this
50+
51+
def reinitializedCopy(): SettingsState =
52+
SettingsState(values.toSeq, changed.toSet)
53+
5054
end SettingsState
5155

5256
case class ArgsSummary(

Diff for: compiler/src/dotty/tools/dotc/inlines/Inlines.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,13 @@ object Inlines:
342342
if Inlines.isInlineable(codeArg1.symbol) then stripTyped(Inlines.inlineCall(codeArg1))
343343
else codeArg1
344344

345+
// We should not be rewriting tested strings
346+
val noRewriteSettings = ctx.settings.rewrite.updateIn(ctx.settingsState.reinitializedCopy(), None)
347+
345348
ConstFold(underlyingCodeArg).tpe.widenTermRefExpr match {
346349
case ConstantType(Constant(code: String)) =>
347350
val source2 = SourceFile.virtual("tasty-reflect", code)
348-
inContext(ctx.fresh.setNewTyperState().setTyper(new Typer(ctx.nestingLevel + 1)).setSource(source2)) {
351+
inContext(ctx.fresh.setSettings(noRewriteSettings).setNewTyperState().setTyper(new Typer(ctx.nestingLevel + 1)).setSource(source2)) {
349352
val tree2 = new Parser(source2).block()
350353
if ctx.reporter.allErrors.nonEmpty then
351354
ctx.reporter.allErrors.map((ErrorKind.Parser, _))

Diff for: compiler/test/dotc/pos-test-pickling.blacklist

+3
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,6 @@ parsercombinators-new-syntax.scala
135135
hylolib-deferred-given
136136
hylolib-cb
137137
hylolib
138+
139+
# typecheckErrors method unpickling
140+
i21415.scala

Diff for: compiler/test/dotc/run-test-pickling.blacklist

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ tuple-zip.scala
2727
tuples1.scala
2828
tuples1a.scala
2929
tuples1b.scala
30-
typeCheckErrors.scala
3130
typeclass-derivation-doc-example.scala
3231
typeclass-derivation1.scala
3332
typeclass-derivation2.scala
@@ -47,3 +46,6 @@ trait-static-forwarder
4746
i17255
4847
named-tuples-strawman-2.scala
4948

49+
# typecheckErrors method unpickling
50+
typeCheckErrors.scala
51+

Diff for: tests/pos/i21415.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//> using options -rewrite -source:3.4-migration
2+
import scala.compiletime.testing.typeCheckErrors
3+
4+
def foo(arg: Int): Unit = ???
5+
6+
@main def Test =
7+
typeCheckErrors("Seq.empty[Int].foreach(foo.apply _)")
8+
typeCheckErrors("Seq.empty[Int].foreach(foo.apply _)")

0 commit comments

Comments
 (0)