Skip to content

Commit 4f8a85c

Browse files
authored
Merge pull request #1586 from dotty-staging/fix/poly-unit
Fix erasure of "def foo[T]: Unit", do not box the return type
2 parents dac5b93 + 6e78c7a commit 4f8a85c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
417417
// See doc comment for ElimByName for speculation how we could improve this.
418418
else MethodType(Nil, Nil, eraseResult(rt))
419419
case tp: PolyType =>
420-
this(tp.resultType) match {
420+
eraseResult(tp.resultType) match {
421421
case rt: MethodType => rt
422422
case rt => MethodType(Nil, Nil, rt)
423423
}

tests/run/unit_erasure.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class A {
2+
def foo1[T]: Unit = {}
3+
def foo2[T](): Unit = {}
4+
def foo3[T]()(): Unit = {}
5+
def foo4: Unit = {}
6+
def foo5(): Unit = {}
7+
def foo6()(): Unit = {}
8+
}
9+
10+
object Test {
11+
def main(args: Array[String]): Unit = {
12+
classOf[A].getMethods.toList.filter(_.getName.startsWith("foo")).foreach { m =>
13+
assert(m.getGenericReturnType == Void.TYPE, s"Method does not return void: `${m}`")
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)