Skip to content

Commit 6ccd6b5

Browse files
committed
Merge pull request #770 from odersky/fix-repeated
Fix repeated
2 parents b779f16 + bc5f076 commit 6ccd6b5

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,15 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
228228
def makeSyntheticParameter(n: Int = 1, tpt: Tree = TypeTree())(implicit ctx: Context): ValDef =
229229
ValDef(nme.syntheticParamName(n), tpt, EmptyTree).withFlags(SyntheticTermParam)
230230

231-
def refOfDef(tree: NameTree)(implicit ctx: Context) = Ident(tree.name)
231+
/** A reference to given definition. If definition is a repeated
232+
* parameter, the reference will be a repeated argument.
233+
*/
234+
def refOfDef(tree: MemberDef)(implicit ctx: Context) = tree match {
235+
case ValDef(_, PostfixOp(_, nme.raw.STAR), _) =>
236+
Typed(Ident(tree.name), Ident(tpnme.WILDCARD_STAR))
237+
case _ =>
238+
Ident(tree.name)
239+
}
232240

233241
// ------- Decorators -------------------------------------------------
234242

src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,9 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
501501
}
502502
ctx.newClassSymbol(owner, name.asTypeName, flags, completer, coord = start)
503503
}
504-
case MODULEsym | VALsym =>
504+
case VALsym =>
505+
ctx.newSymbol(owner, name.asTermName, flags, localMemberUnpickler, coord = start)
506+
case MODULEsym =>
505507
if (isModuleRoot) {
506508
moduleRoot setFlag flags
507509
moduleRoot.symbol
@@ -546,6 +548,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
546548
if (tag == ALIASsym) TypeAlias(tp1)
547549
else if (denot.isType) checkNonCyclic(denot.symbol, tp1, reportErrors = false)
548550
// we need the checkNonCyclic call to insert LazyRefs for F-bounded cycles
551+
else if (!denot.is(Param)) tp1.underlyingIfRepeated(isJava = false)
549552
else tp1
550553
if (denot.isConstructor) addConstructorTypeParams(denot)
551554
if (atEnd) {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,21 @@ class TreeChecker extends Phase with SymTransformer {
228228
}
229229
}.apply(tp)
230230

231+
def checkNotRepeated(tree: Tree)(implicit ctx: Context): tree.type = {
232+
assert(!tree.tpe.widen.isRepeatedParam, i"repeated parameter type not allowed here: $tree")
233+
tree
234+
}
235+
231236
override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): Tree = {
232237
assert(tree.isTerm || !ctx.isAfterTyper, tree.show + " at " + ctx.phase)
233238
assert(tree.isType || !needsSelect(tree.tpe), i"bad type ${tree.tpe} for $tree # ${tree.uniqueId}")
234239
assertDefined(tree)
235-
super.typedIdent(tree, pt)
240+
checkNotRepeated(super.typedIdent(tree, pt))
236241
}
237242

238243
override def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = {
239244
assert(tree.isTerm || !ctx.isAfterTyper, tree.show + " at " + ctx.phase)
240-
super.typedSelect(tree, pt)
245+
checkNotRepeated(super.typedSelect(tree, pt))
241246
}
242247

243248
override def typedThis(tree: untpd.This)(implicit ctx: Context) = {

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
577577
val inferredParams: List[untpd.ValDef] =
578578
for ((param, i) <- params.zipWithIndex) yield
579579
if (!param.tpt.isEmpty) param
580-
else cpy.ValDef(param)(tpt = untpd.TypeTree(inferredParamType(param, protoFormal(i))))
580+
else cpy.ValDef(param)(
581+
tpt = untpd.TypeTree(
582+
inferredParamType(param, protoFormal(i)).underlyingIfRepeated(isJava = false)))
581583

582584
// Define result type of closure as the expected type, thereby pushing
583585
// down any implicit searches. We do this even if the expected type is not fully

tests/run/i768.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
case class A(a: String*){
2+
val s = a.toString
3+
}
4+
5+
object Test {
6+
def main(args: Array[String]) =
7+
assert(A("a", "bc").s == "WrappedArray(a, bc)")
8+
}
9+
10+

0 commit comments

Comments
 (0)