@@ -27,7 +27,7 @@ import typer.ConstFold
27
27
import typer .Checking .checkNonCyclic
28
28
import typer .Nullables ._
29
29
import util .Spans ._
30
- import util .SourceFile
30
+ import util .{ SourceFile , Property }
31
31
import ast .{Trees , tpd , untpd }
32
32
import Trees ._
33
33
import Decorators ._
@@ -1135,7 +1135,23 @@ class TreeUnpickler(reader: TastyReader,
1135
1135
tpd.Super (qual, mixId, mixTpe.typeSymbol)
1136
1136
case APPLY =>
1137
1137
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 , ())
1139
1155
case TYPEAPPLY =>
1140
1156
tpd.TypeApply (readTerm(), until(end)(readTpt()))
1141
1157
case TYPED =>
@@ -1523,4 +1539,9 @@ object TreeUnpickler {
1523
1539
inline val AllDefs = 2 // add everything
1524
1540
1525
1541
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 ()
1526
1547
}
0 commit comments