File tree 4 files changed +25
-0
lines changed
compiler/src/dotty/tools/dotc/core
library/src/scala/annotation
4 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -868,6 +868,10 @@ class Definitions {
868
868
def ShowAsInfixAnnot (implicit ctx : Context ): ClassSymbol = ShowAsInfixAnotType .symbol.asClass
869
869
lazy val FunctionalInterfaceAnnotType = ctx.requiredClassRef(" java.lang.FunctionalInterface" )
870
870
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
871
875
872
876
// convenient one-parameter method types
873
877
def methOfAny (tp : Type ): MethodType = MethodType (List (AnyType ), tp)
Original file line number Diff line number Diff line change
1
+ package scala .annotation
2
+
3
+ final class alpha (name : String ) extends StaticAnnotation
Original file line number Diff line number Diff line change
1
+ package scala .annotation
2
+
3
+ final class infix extends StaticAnnotation
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments