New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotations on abstract vals should emit a warning before they silently disappear #6375

Open
scabug opened this Issue Sep 15, 2012 · 7 comments

Comments

Projects
None yet
1 participant
@scabug

scabug commented Sep 15, 2012

Annotation on a val is by default added to the underlying field of a val.

If a val in question is abstract, there's no underlying field, so the annotation goes to waste. Writing @( @scala.annotation.meta.getter) would attach the annotation to the getter as desired, but it's not obvious.

Therefore I propose we emit a warning when an annotation is going to silently disappear.

@scabug

This comment has been minimized.

scabug commented Sep 15, 2012

@scabug

This comment has been minimized.

scabug commented Sep 15, 2012

@xeno-by said:
Related: #6325

@scabug

This comment has been minimized.

scabug commented Dec 22, 2012

@scabug

This comment has been minimized.

scabug commented May 17, 2013

@paulp said:
dc1b7d5

@scabug

This comment has been minimized.

scabug commented Jun 12, 2015

Guillaume Massé (masgui) said (edited on Jun 12, 2015 7:31:25 PM UTC):
The parser wont accept annotation with paramers:

cat A.scala

import scala.annotation.meta.param
import scala.annotation.StaticAnnotation
class Foo(a: Int) extends StaticAnnotation
case class Anotated(@(Foo(1) @param) p1: Int)

/nix/store/22dsrlsqp33kqarh4cb9d7dis4kwgvma-scala-2.10.4/bin/scalac A.scala

A.scala:4: error: ')' expected but '(' found.
case class Anotated(@(Foo(1) @param) p1: Int)
                         ^
A.scala:4: error: identifier expected but ')' found.
case class Anotated(@(Foo(1) @param) p1: Int)
                                   ^
A.scala:4: error: ':' expected but eof found.
case class Anotated(@(Foo(1) @param) p1: Int)
                                             ^
three errors found

/nix/store/8ws1mx6fvgf3hijc49356vmm2q4zxzcj-scala-2.11.6/bin/scalac A.scala

A.scala:4: error: ')' expected but '(' found.
case class Anotated(@(Foo(1) @param) p1: Int)
                         ^
A.scala:4: error: identifier expected but ')' found.
case class Anotated(@(Foo(1) @param) p1: Int)
                                   ^
A.scala:4: error: ':' expected but eof found.
case class Anotated(@(Foo(1) @param) p1: Int)
                                             ^
three errors found
@scabug

This comment has been minimized.

scabug commented Aug 11, 2016

@lrytz said:
scala/scala#5141 drops the warnings (commit 4b657bbe384bd364035060d3702d321b488e9263). Commit message: "Drop warning on potentially discarded annotations, I don't think this warrants a warning".

@scabug

This comment has been minimized.

scabug commented Aug 11, 2016

@paulp said:
Is the theory that people often annotate members with the intention of that annotation being silently discarded?

Scoreboard: Implementor convenience N+1, User 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment