Skip to content

Commit ca07c71

Browse files
committed
Merge pull request #572 from dotty-staging/fix/#569-newRefArray
Fix/#569 new ref array
2 parents 93667be + 36ab621 commit ca07c71

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,16 +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 = sym.info.resultType
472+
var effectiveSym = sym
473+
if (sym == defn.newRefArrayMethod) {
474+
// newRefArray is treated specially: It's the only 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
473483
val ddef1 = untpd.cpy.DefDef(ddef)(
474484
tparams = Nil,
475-
vparamss = (outer.paramDefs(sym) ::: ddef.vparamss.flatten) :: Nil,
485+
vparamss = (outer.paramDefs(effectiveSym) ::: ddef.vparamss.flatten) :: Nil,
476486
tpt = untpd.TypedSplice(TypeTree(restpe).withPos(ddef.tpt.pos)),
477487
rhs = ddef.rhs match {
478488
case id @ Ident(nme.WILDCARD) => untpd.TypedSplice(id.withType(restpe))
479489
case _ => ddef.rhs
480490
})
481-
super.typedDefDef(ddef1, sym)
491+
super.typedDefDef(ddef1, effectiveSym)
482492
}
483493

484494
/** After erasure, we may have to replace the closure method by a bridge.
@@ -600,7 +610,7 @@ object Erasure extends TypeTestsCasts{
600610

601611
traverse(newStats, oldStats)
602612
}
603-
613+
604614
private final val NoBridgeFlags = Flags.Accessor | Flags.Deferred | Flags.Lazy
605615

606616
/** Create a bridge DefDef which overrides a parent method.

0 commit comments

Comments
 (0)