@@ -6,6 +6,7 @@ import scala.language.unsafeNulls
66
77import scala .annotation .{switch , tailrec }
88import scala .collection .mutable .SortedMap
9+ import scala .jdk .CollectionConverters .*
910
1011import scala .tools .asm
1112import scala .tools .asm .{Handle , Opcodes }
@@ -781,6 +782,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
781782 // we have to 'simulate' it by DUPlicating the freshly created
782783 // instance (on JVM, <init> methods return VOID).
783784 case Apply (fun @ DesugaredSelect (New (tpt), nme.CONSTRUCTOR ), args) =>
785+ println(s " DEBUG: New(tpt = $tpt) at ${app.span}" )
784786 val ctor = fun.symbol
785787 assert(ctor.isClassConstructor, s " 'new' call to non-constructor: ${ctor.name}" )
786788
@@ -793,13 +795,19 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
793795
794796 case rt : ClassBType =>
795797 assert(classBTypeFromSymbol(ctor.owner) == rt, s " Symbol ${ctor.owner.showFullName} is different from $rt" )
796- mnode.visitTypeInsn(asm.Opcodes .NEW , rt.internalName)
798+ val retType = app.getAttachment(InvokeReturnType )
799+ val instrType = fun.getAttachment(InstructionTypeArguments )
800+ val instrJType = instrType.getOrElse(Nil ).map(bc.toJTypeA).asJava
801+ // println(s"NEW with retType = $retType and instrType = $instrType")
802+ mnode.visitTypeInsn(asm.Opcodes .NEW , rt.internalName, instrJType)
797803 bc dup generatedType
798804 stack.push(rt)
799805 stack.push(rt)
800806 genLoadArguments(args, paramTKs(app))
801807 stack.pop(2 )
802- genCallMethod(ctor, InvokeStyle .Special , app.span)
808+ genCallMethod(ctor, InvokeStyle .Special , app.span,
809+ invokeReturnType = retType,
810+ instrTypeArgs = instrType)
803811
804812 case _ =>
805813 abort(s " Cannot instantiate $tpt of kind: $generatedType" )
@@ -1457,20 +1465,16 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
14571465 val staticDesc = MethodBType (ownerBType :: bmType.argumentTypes, bmType.returnType).descriptor
14581466 val staticName = traitSuperAccessorName(method)
14591467 bc.invokestatic(receiverName, staticName, staticDesc, isInterface)
1460- // bc.invokestatic(receiverName, staticName, staticDesc, isInterface, invokeReturnType, instrTypeArgs)
14611468 } else {
14621469 bc.invokespecial(receiverName, jname, mdescr, isInterface)
1463- // bc.invokespecial(receiverName, jname, mdescr, isInterface, invokeReturnType, instrTypeArgs)
14641470 }
14651471 } else {
14661472 val opc = style match {
14671473 case Static => Opcodes .INVOKESTATIC
14681474 case Special => Opcodes .INVOKESPECIAL
14691475 case Virtual => if (isInterface) Opcodes .INVOKEINTERFACE else Opcodes .INVOKEVIRTUAL
14701476 }
1471- // println("genCallMethod" + method.show + " : " + method.getAnnotation(defn.ErasurePreservationAnnot))
14721477 bc.emitInvoke(opc, receiverName, jname, mdescr, isInterface, invokeReturnType, instrTypeArgs)
1473- // bc.emitInvoke(opc, receiverName, jname, mdescr, isInterface, invokeReturnType, instrTypeArgs)
14741478 }
14751479
14761480 bmType.returnType
0 commit comments