Skip to content

Commit 00a839e

Browse files
committed
Make TreeUnpickler read pre-3.2 Tasty files correctly
This is needed to ensure backwards Tasty compatibility
1 parent 2fc2aa2 commit 00a839e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import typer.ConstFold
2727
import typer.Checking.checkNonCyclic
2828
import typer.Nullables._
2929
import util.Spans._
30-
import util.SourceFile
30+
import util.{SourceFile, Property}
3131
import ast.{Trees, tpd, untpd}
3232
import Trees._
3333
import Decorators._
@@ -1135,7 +1135,23 @@ class TreeUnpickler(reader: TastyReader,
11351135
tpd.Super(qual, mixId, mixTpe.typeSymbol)
11361136
case APPLY =>
11371137
val fn = readTerm()
1138-
tpd.Apply(fn, until(end)(readTerm()))
1138+
val args = until(end)(readTerm())
1139+
// Adapt constructor calls where class has only using clauses from old to new scheme.
1140+
// Old: leading (), new: trailing ().
1141+
// This is neccessary so that we can read pre-3.2 Tasty correctly. There,
1142+
// constructor calls use the old scheme, but constructor definitions already
1143+
// use the new scheme, since they are reconstituted with normalizeIfConstructor.
1144+
if fn.symbol.isConstructor && fn.tpe.widen.isContextualMethod && args.isEmpty then
1145+
fn.withAttachment(SuppressedApplyToNone, ())
1146+
else
1147+
val res = tpd.Apply(fn, args)
1148+
if fn.removeAttachment(SuppressedApplyToNone).isEmpty then
1149+
res
1150+
else res.tpe.widen match
1151+
case MethodType(Nil) =>
1152+
res.appliedToNone
1153+
case mt: MethodType if mt.isContextualMethod =>
1154+
res.withAttachment(SuppressedApplyToNone, ())
11391155
case TYPEAPPLY =>
11401156
tpd.TypeApply(readTerm(), until(end)(readTpt()))
11411157
case TYPED =>
@@ -1523,4 +1539,9 @@ object TreeUnpickler {
15231539
inline val AllDefs = 2 // add everything
15241540

15251541
class TreeWithoutOwner extends Exception
1542+
1543+
/** An attachment key indicating that an old-style leading () in a constructor
1544+
* call that has otherwise only using clauses was suppressed.
1545+
*/
1546+
val SuppressedApplyToNone: Property.Key[Unit] = Property.Key()
15261547
}

0 commit comments

Comments
 (0)