Skip to content

Commit bdfc9e8

Browse files
committed
Fix #7972: Disallow signatures with _:* return types
1 parent 842e4c4 commit bdfc9e8

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,11 @@ trait Checking {
938938
errorTree(tpt, MissingTypeParameterFor(tpt.tpe))
939939
else tpt
940940

941+
/** Check that the signature of the class mamber does not return a repeated parameter type */
942+
def checkSignatureRepeatedParam(sym: Symbol)(implicit ctx: Context): Unit =
943+
if (sym.maybeOwner.isClass && sym.info.finalResultType.isRepeatedParam)
944+
ctx.error(em"Cannot return repeated parameter type ${sym.info.finalResultType}", sym.sourcePos)
945+
941946
/** Verify classes extending AnyVal meet the requirements */
942947
def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context): Unit =
943948
Checking.checkDerivedValueClass(clazz, stats)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,7 @@ class Typer extends Namer
16091609
case rhs => typedExpr(rhs, tpt1.tpe.widenExpr)
16101610
}
16111611
val vdef1 = assignType(cpy.ValDef(vdef)(name, tpt1, rhs1), sym)
1612+
checkSignatureRepeatedParam(sym)
16121613
if (sym.is(Inline, butNot = DeferredOrTermParamOrAccessor))
16131614
checkInlineConformant(rhs1, isFinal = sym.is(Final), em"right-hand side of inline $sym")
16141615
patchFinalVals(vdef1)
@@ -1694,7 +1695,9 @@ class Typer extends Namer
16941695
checkThisConstrCall(rhs1)
16951696
}
16961697

1697-
assignType(cpy.DefDef(ddef)(name, tparams1, vparamss1, tpt1, rhs1), sym).setDefTree
1698+
val ddef2 = assignType(cpy.DefDef(ddef)(name, tparams1, vparamss1, tpt1, rhs1), sym)
1699+
checkSignatureRepeatedParam(sym)
1700+
ddef2.setDefTree
16981701
//todo: make sure dependent method types do not depend on implicits or by-name params
16991702
}
17001703

tests/neg/i7972.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
object O {
2+
def m1(a: Int*) = (a: _*) // error: Cannot return repeated parameter type Int*
3+
def m2(a: Int*) = { // error: Cannot return repeated parameter type Int*
4+
val b = (a: _*)
5+
b
6+
}
7+
def m3(a: Int*): Any = {
8+
val b = (a: _*) // Ok, does not affect the signature
9+
b
10+
}
11+
def m4(a: 2*) = (a: _*) // error: Cannot return repeated parameter type Int*
12+
13+
}
14+
15+
class O(a: Int*) {
16+
val m = (a: _*) // error: Cannot return repeated parameter type Int*
17+
}
18+

0 commit comments

Comments
 (0)