Skip to content
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

Scala annotation yields warning about "no valid targets" #8813

Closed
scabug opened this issue Aug 23, 2014 · 7 comments
Closed

Scala annotation yields warning about "no valid targets" #8813

scabug opened this issue Aug 23, 2014 · 7 comments

Comments

@scabug
Copy link

scabug commented Aug 23, 2014

This seems to work in Scala 2.10.4 but no more in Scala 2.11.x.

Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51).
Type in expressions to have them evaluated.
Type :help for more information.

scala> class annot extends scala.annotation.StaticAnnotation
defined class annot

scala> trait A { @annot val x: Int }
defined trait A

scala> :q

[success] Total time: 62 s, completed Aug 23, 2014 9:13:32 PM
> ++ 2.11.2
[info] Setting version to 2.11.2
[info] Set current project to REPL (in build file:/Users/leo/REPL/)
> console
Welcome to Scala version 2.11.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51).
Type in expressions to have them evaluated.
Type :help for more information.

scala> class annot extends scala.annotation.StaticAnnotation
defined class annot

scala> trait A { @annot val x: Int }
<console>:8: warning: no valid targets for annotation on value x - it is discarded unused. You may specify targets with meta-annotations, e.g. @(annot @getter)
       trait A { @annot val x: Int }
                  ^
defined trait A
@scabug
Copy link
Author

scabug commented Aug 23, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8813?orig=1
Reporter: Leonard Schneider (leonard.schneider)
Affected Versions: 2.11.1, 2.11.2, 2.11.5, 2.11.8

@scabug
Copy link
Author

scabug commented Aug 23, 2014

Leonard Schneider (leonard.schneider) said:
I've just realized this warning was intended for reflection about annotation, which is precisely what I wanted to do. See #6325.

@scabug
Copy link
Author

scabug commented Oct 14, 2014

Tim Feuerbach (tfeuerbach) said:
The warning should not be issued for annotations that are elided by the compiler anyway, e.g. @BeanProperty:

scala> trait A {@BeanProperty var x: Int }
<console>:8: warning: no valid targets for annotation on method x - it is discarded unused. You may specify targets with meta-annotations, e.g. @(scala.beans.BeanProperty @getter)
       trait A {@BeanProperty var x: Int }

@scabug
Copy link
Author

scabug commented Jan 12, 2015

Andrei Pozolotin (andrei.pozolotin) said:
still affects 2.11.5 both java and scala annotations

@scabug
Copy link
Author

scabug commented Feb 13, 2015

Helena Edelson (helena) said (edited on Feb 13, 2015 3:45:39 PM UTC):
I am trying to upgrade our project to scala 2.11 and add a cross build and see this same compiler error with Scala 2.11.0 through 5 with: (for sc and rtf @transient)

{code}
class CassandraRDD[R] private[connector] (
@transient sc: SparkContext,
val connector: CassandraConnector,
val keyspaceName: String,
val tableName: String,
val columnNames: ColumnSelector = AllColumns,
val where: CqlWhereClause = CqlWhereClause.empty,
val readConf: ReadConf = ReadConf())(
implicit
ct : ClassTag[R], @transient rtf: RowReaderFactory[R])
extends RDD[R](sc, Seq.empty) with Logging{code}

Same compiler error if I use these against 2.11.0 - 5:
@(transient @scala.annotation.meta.field)
@(transient @scala.annotation.meta.getter)

@scabug
Copy link
Author

scabug commented Feb 13, 2015

Helena Edelson (helena) said (edited on Feb 13, 2015 4:04:31 PM UTC):
This compiles by 'var' or 'val'-ing the @transient

{code}class CassandraRDD[R] private[connector] (@transient var sc: SparkContext ...){code}

@som-snytt
Copy link

Currently relevant ticket is: #6375 as to whether to bring back the warning vilified here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants