Skip to content

Commit 5ec51f2

Browse files
Merge pull request #8761 from dotty-staging/add-regression-test
Add inline override regression test
2 parents 1ce0885 + 375bc2f commit 5ec51f2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/run/inline-override-num.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
trait Num[T] {
2+
def plus(x: T, y: T): T
3+
}
4+
5+
object Num {
6+
class IntNum extends Num[Int] {
7+
inline def plus(inline x: Int, inline y: Int): Int = x + y
8+
}
9+
given IntNum
10+
11+
extension Extension on [T](inline x: T)(using inline num: Num[T]) {
12+
inline def +(inline y: T): T = num.plus(x, y)
13+
}
14+
}
15+
16+
import Num.Extension._
17+
18+
inline def twiceInlined[T: Num](x : T): T = x + x
19+
def twice[T: Num](x : T): T = x + x
20+
21+
@main def Test =
22+
val x: Int = 3
23+
assert(6 == twiceInlined(x)) // code will be x + x using the primitive Int.+
24+
assert(6 == twice(x)) // will call IntNum.plus through virtual dispatch

0 commit comments

Comments
 (0)