Skip to content

Commit 4e62869

Browse files
committed
Fix scala#6750: Use semi-erased by name parameter signature
Before `Erasure` the signatures will contain `=>X` instead of `Function0`. This makes signature clashes of by-name parameters only show up after `Erasure`. This allows for `inline` methods to have by-name parameter overloads.
1 parent fef0607 commit 4e62869

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,9 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
608608
case tp: TermRef =>
609609
sigName(tp.widen)
610610
case ExprType(rt) =>
611-
sigName(defn.FunctionOf(Nil, rt))
611+
// Before erasure the signature will be `=>X` and after erasure it will be `Function0`
612+
if (ctx.phase.erasedTypes) sigName(defn.FunctionOf(Nil, rt))
613+
else tpnme.ARROWkw ++ sigName(rt)
612614
case tp: TypeVar =>
613615
val inst = tp.instanceOpt
614616
if (inst.exists) sigName(inst) else tpnme.Uninstantiated

tests/neg/i6750.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Foo {
2+
def bar(i: => Int): Unit = ???
3+
def bar(l: => Long): Unit = ??? // error
4+
}

tests/neg/i6750b.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Foo {
2+
def bar(i: => Int): Unit = ???
3+
def bar(l: () => Long): Unit = ??? // error
4+
}

tests/pos/i6750.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Foo {
2+
inline def foo(i: => Int): Unit = ???
3+
inline def foo(l: => Long): Unit = ???
4+
5+
foo(2)
6+
foo(3L)
7+
}

tests/run/i6750.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
object Test {
3+
4+
inline def foo(i: => Int) = i + i
5+
inline def foo(l: => Long) = l * l
6+
7+
inline def bar(i: () => Int) = ???
8+
inline def bar[T](x: () => T) = ???
9+
10+
def main(args: Array[String]): Unit = {
11+
assert(10 == foo(5))
12+
assert(25L == foo(5L))
13+
14+
}
15+
16+
}

0 commit comments

Comments
 (0)