@@ -176,8 +176,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
176176 /** A map from symbols to their associated `decls` scopes */
177177 private val symScopes = mutable.AnyRefMap [Symbol , Scope ]()
178178
179- /** A dummy buffer to pass to `readType` when no `rawParamss` are collected */
180- private val throwAwayBuffer = new ListBuffer [ List [Symbol ]]
179+ /** A mapping from method types to the parameters used in constructing them */
180+ private val paramsOfMethodType = new java.util. IdentityHashMap [ MethodType , List [Symbol ]]
181181
182182 protected def errorBadSignature (msg : String , original : Option [RuntimeException ] = None )(implicit ctx : Context ): Nothing = {
183183 val ex = new BadSignature (
@@ -452,12 +452,6 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
452452 val owner = readSymbolRef()
453453
454454 var flags = unpickleScalaFlags(readLongNat(), name.isTypeName)
455- if (flags.isAllOf(DefaultParameter )) {
456- // DefaultParameterized flag now on method, not parameter
457- // assert(flags.is(Param), s"$name0 in $owner")
458- flags = flags &~ DefaultParameterized
459- owner.setFlag(DefaultParameterized )
460- }
461455
462456 name = name.adjustIfModuleClass(flags)
463457 if (flags.is(Method ))
@@ -564,6 +558,15 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
564558
565559 class LocalUnpickler extends LazyType {
566560 def startCoord (denot : SymDenotation ): Coord = denot.symbol.coord
561+
562+ def paramssOfType (tp : Type ): List [List [Symbol ]] = tp match
563+ case TempPolyType (tparams, restpe) => tparams :: paramssOfType(restpe)
564+ case mt : MethodType =>
565+ val params = paramsOfMethodType.remove(mt)
566+ val rest = paramssOfType(mt.resType)
567+ if params == null then rest else params :: rest
568+ case _ => Nil
569+
567570 def complete (denot : SymDenotation )(implicit ctx : Context ): Unit = try {
568571 def parseToCompletion (denot : SymDenotation )(implicit ctx : Context ) = {
569572 val tag = readByte()
@@ -577,11 +580,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
577580 if (isSymbolRef(inforef)) inforef = readNat()
578581
579582 // println("reading type for " + denot) // !!! DEBUG
580- val paramssBuf =
581- if denot.is(Method ) then new ListBuffer [List [Symbol ]]
582- else throwAwayBuffer
583- val tp = at(inforef, () => readType(paramssBuf)(ctx))
584- if denot.is(Method ) then denot.rawParamss = paramssBuf.toList
583+ val tp = at(inforef, () => readType()(ctx))
584+ if denot.is(Method ) then denot.rawParamss = paramssOfType(tp)
585585
586586 denot match {
587587 case denot : ClassDenotation if ! isRefinementClass(denot.symbol) =>
@@ -728,7 +728,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
728728 * the flag say that a type of kind * is expected, so that PolyType(tps, restpe) can be disambiguated to PolyType(tps, NullaryMethodType(restpe))
729729 * (if restpe is not a ClassInfoType, a MethodType or a NullaryMethodType, which leaves TypeRef/SingletonType -- the latter would make the polytype a type constructor)
730730 */
731- protected def readType (paramssBuf : ListBuffer [ List [ Symbol ]] )(implicit ctx : Context ): Type = {
731+ protected def readType ()(implicit ctx : Context ): Type = {
732732 val tag = readByte()
733733 val end = readNat() + readIndex
734734 (tag : @ switch) match {
@@ -797,15 +797,15 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
797797 case METHODtpe | IMPLICITMETHODtpe =>
798798 val restpe = readTypeRef()
799799 val params = until(end, () => readSymbolRef())
800- if params.nonEmpty then paramssBuf += params
801800 val maker = MethodType .companion(
802801 isImplicit = tag == IMPLICITMETHODtpe || params.nonEmpty && params.head.is(Implicit ))
803- maker.fromSymbols(params, restpe)
802+ val result = maker.fromSymbols(params, restpe)
803+ if params.nonEmpty then paramsOfMethodType.put(result, params)
804+ result
804805 case POLYtpe =>
805806 val restpe = readTypeRef()
806807 val typeParams = until(end, () => readSymbolRef())
807808 if typeParams.nonEmpty then
808- paramssBuf += typeParams
809809 TempPolyType (typeParams.asInstanceOf [List [TypeSymbol ]], restpe.widenExpr)
810810 else
811811 ExprType (restpe)
@@ -892,7 +892,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
892892 at(readNat(), () => readDisambiguatedSymbol(p)())
893893
894894 protected def readNameRef ()(implicit ctx : Context ): Name = at(readNat(), () => readName())
895- protected def readTypeRef ()(implicit ctx : Context ): Type = at(readNat(), () => readType(throwAwayBuffer )) // after the NMT_TRANSITION period, we can leave off the () => ... ()
895+ protected def readTypeRef ()(implicit ctx : Context ): Type = at(readNat(), () => readType()) // after the NMT_TRANSITION period, we can leave off the () => ... ()
896896 protected def readConstantRef ()(implicit ctx : Context ): Constant = at(readNat(), () => readConstant())
897897
898898 protected def readTypeNameRef ()(implicit ctx : Context ): TypeName = readNameRef().toTypeName
0 commit comments