Two Scala annotations

bearophile bearophileHUGS at lycos.com
Sun May 27 06:13:36 PDT 2012


I have found two Scala annotations.

1) The first one is @switch:
http://www.scala-lang.org/api/current/scala/annotation/switch.html

Currently this D2 code compiles:

void main() {
     int x = 2;
     int y = 2;
     switch(x) {
         case 1: break;
         case y: break;
         default:
     }
}

I think that accepting that "case y" is a compiler bug, because y 
is a run-time value, that kills some switch optimization 
possibilities.

Inside D code the presence or absence of an annotation 
semantically related to that Scala @switch is able to disallow / 
allow the presence of a run-time value among the cases.

------------------

2) The second is @implicitNotFound:
http://www.scala-lang.org/api/current/scala/annotation/implicitNotFound.html

More info:
http://suereth.blogspot.it/2011/03/annotate-your-type-classes.html

Maybe a related idea is able to improve/add error messages when 
certain template constraints fail (to be used when you have just 
1 template, where constraints failure means wrong input or 
something clearly missing in user code).

Bye,
bearophile


More information about the Digitalmars-d mailing list