Skip to content

Commit d01a0c9

Browse files
oderskyDarkDimius
authored andcommitted
Better fix for $569
We now provide a ndew symbol for the `newRefArray` definition, which makes any further treatment after erasure unnecessary.
1 parent 07f346e commit d01a0c9

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -469,20 +469,26 @@ object Erasure extends TypeTestsCasts{
469469
tpt = untpd.TypedSplice(TypeTree(sym.info).withPos(vdef.tpt.pos))), sym)
470470

471471
override def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(implicit ctx: Context) = {
472-
val restpe =
473-
if (sym == defn.newRefArrayMethod) defn.ObjectType
474-
// newRefArray is the only source defined method that's polymorphic
475-
// after erasure; needs to be treated specially
476-
else sym.info.resultType
472+
var effectiveSym = sym
473+
if (sym == defn.newRefArrayMethod) {
474+
// newRefArray is treated specially: It's new only method source-defined method
475+
// that has a polymorphic type after erasure. But treating its (dummy) definition
476+
// with a polymorphic type at and after erasure is an awkward special case.
477+
// We therefore rewrite the method definition with a new Symbol of type
478+
// (length: Int)Object
479+
val MethodType(pnames, ptypes) = sym.info.resultType
480+
effectiveSym = sym.copy(info = MethodType(pnames, ptypes, defn.ObjectType))
481+
}
482+
val restpe = effectiveSym.info.resultType
477483
val ddef1 = untpd.cpy.DefDef(ddef)(
478484
tparams = Nil,
479-
vparamss = (outer.paramDefs(sym) ::: ddef.vparamss.flatten) :: Nil,
485+
vparamss = (outer.paramDefs(effectiveSym) ::: ddef.vparamss.flatten) :: Nil,
480486
tpt = untpd.TypedSplice(TypeTree(restpe).withPos(ddef.tpt.pos)),
481487
rhs = ddef.rhs match {
482488
case id @ Ident(nme.WILDCARD) => untpd.TypedSplice(id.withType(restpe))
483489
case _ => ddef.rhs
484490
})
485-
super.typedDefDef(ddef1, sym)
491+
super.typedDefDef(ddef1, effectiveSym)
486492
}
487493

488494
/** After erasure, we may have to replace the closure method by a bridge.

0 commit comments

Comments
 (0)