We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b3f2aee commit 375bc2fCopy full SHA for 375bc2f
tests/run/inline-override-num.scala
@@ -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