Skip to content

Commit 259ecea

Browse files
committed
Add alpha and infix annotations
1 parent fda1250 commit 259ecea

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,10 @@ class Definitions {
868868
def ShowAsInfixAnnot(implicit ctx: Context): ClassSymbol = ShowAsInfixAnotType.symbol.asClass
869869
lazy val FunctionalInterfaceAnnotType = ctx.requiredClassRef("java.lang.FunctionalInterface")
870870
def FunctionalInterfaceAnnot(implicit ctx: Context) = FunctionalInterfaceAnnotType.symbol.asClass
871+
lazy val InfixAnnotType = ctx.requiredClassRef("scala.annotation.infix")
872+
def InfixAnnot(implicit ctx: Context) = InfixAnnotType.symbol.asClass
873+
lazy val AlphaAnnotType = ctx.requiredClassRef("scala.annotation.alpha")
874+
def AlphaAnnot(implicit ctx: Context) = AlphaAnnotType.symbol.asClass
871875

872876
// convenient one-parameter method types
873877
def methOfAny(tp: Type): MethodType = MethodType(List(AnyType), tp)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package scala.annotation
2+
3+
final class alpha(name: String) extends StaticAnnotation
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package scala.annotation
2+
3+
final class infix extends StaticAnnotation

tests/run/infix.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import annotation.{infix, alpha}
2+
object Test extends App {
3+
4+
case class Rational(n: Int, d: Int) {
5+
@infix def + (that: Rational) =
6+
Rational(this.n * that.d + that.n * this.d, this.d * that.d)
7+
@infix @alpha("multiply") def * (that: Rational) =
8+
Rational(this.n * that.n, this.d * that.d)
9+
}
10+
11+
val r1 = Rational(1,2)
12+
val r2 = Rational(2,3)
13+
println(r1 * r2)
14+
println(r1 + r2)
15+
}

0 commit comments

Comments
 (0)