@@ -27,7 +27,7 @@ import typer.ConstFold
2727import typer .Checking .checkNonCyclic
2828import typer .Nullables ._
2929import util .Spans ._
30- import util .SourceFile
30+ import util .{ SourceFile , Property }
3131import ast .{Trees , tpd , untpd }
3232import Trees ._
3333import 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