Skip to content

Commit 0f58146

Browse files
committed
Add alpha and infix annotations
1 parent b537220 commit 0f58146

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
@@ -877,6 +877,10 @@ class Definitions {
877877
def ShowAsInfixAnnot(implicit ctx: Context): ClassSymbol = ShowAsInfixAnotType.symbol.asClass
878878
lazy val FunctionalInterfaceAnnotType = ctx.requiredClassRef("java.lang.FunctionalInterface")
879879
def FunctionalInterfaceAnnot(implicit ctx: Context) = FunctionalInterfaceAnnotType.symbol.asClass
880+
lazy val InfixAnnotType = ctx.requiredClassRef("scala.annotation.infix")
881+
def InfixAnnot(implicit ctx: Context) = InfixAnnotType.symbol.asClass
882+
lazy val AlphaAnnotType = ctx.requiredClassRef("scala.annotation.alpha")
883+
def AlphaAnnot(implicit ctx: Context) = AlphaAnnotType.symbol.asClass
880884

881885
// convenient one-parameter method types
882886
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)