Skip to content

Annotations import fails when imported in class scope #2109

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

Closed
felixmulder opened this issue Mar 16, 2017 · 3 comments
Closed

Annotations import fails when imported in class scope #2109

felixmulder opened this issue Mar 16, 2017 · 3 comments

Comments

@felixmulder
Copy link
Contributor

felixmulder commented Mar 16, 2017

// Foo.scala
class Foo {
  import foo.Annot

  @Annot def foo = ()
}
// Annot.java
package foo;
import java.lang.annotation.*;

public @interface Annot {}

compiles with:

-- [E006] Unbound Identifier Error: local/test.scala ---------------------------
4 |  @Annot def foo = ()
  |   ^^^^^
  |   not found: type Annot

longer explanation available when compiling with `-explain`
-- Error: local/test.scala -----------------------------------------------------
2 |  import foo.Annot
  |         ^^^
  |         => Unit(Foo.this.foo) is not stable

whereas:

import foo.Annot
class Foo {
  @Annot def foo = ()
}

Compiles just fine.

@odersky
Copy link
Contributor

odersky commented Jul 20, 2017

This one might be unavoidable. Annotations in dotty have semantic meaning - they can rewrite the tree they annotate. This means we need to know what they are beforehand. There's an intricate dance when to look at what, which is unfortunately incompatible with the use pattern shown here.

@odersky
Copy link
Contributor

odersky commented Jan 24, 2018

We might want to revert the decision to evaluate annotations early. It will depend how our plans for meta programming shape up in general.

@smarter
Copy link
Member

smarter commented Jan 28, 2019

Already fixed, regression test in #5800.

@smarter smarter closed this as completed Jan 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants