Skip to content

@targetName on toplevel class/trait/object fails separate compilation #15066

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
griggt opened this issue Apr 28, 2022 · 2 comments · Fixed by #15068
Closed

@targetName on toplevel class/trait/object fails separate compilation #15066

griggt opened this issue Apr 28, 2022 · 2 comments · Fixed by #15068
Milestone

Comments

@griggt
Copy link
Contributor

griggt commented Apr 28, 2022

Compiler version

3.2.0-RC1-bin-20220427-b1f00a7-NIGHTLY and earlier

Minimized code

Foo.scala

@annotation.targetName("Bar") class Foo:
  def it: Int = 42

Test.scala

@main def Test = println(Foo().it)

Output

$ scalac Foo.scala
$ scalac Test.scala
-- [E006] Not Found Error: Test.scala:1:25 -------------------------------------
1 |@main def Test = println(Foo().it)
  |                         ^^^
  |                         Not found: Foo
  |
  | longer explanation available when compiling with `-explain`
1 error found

Expectation

I understand that supporting @targetName on class/trait/object is intentional (see #11969 (comment)), thus I would expect such usage to work with separate compilation.

Remarks

No issue with joint compilation.
No issue if Foo is an inner class.

@griggt griggt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 28, 2022
@griggt
Copy link
Contributor Author

griggt commented Apr 28, 2022

I don't see an efficient way to support this, since the symbol loader determines the entered symbol name from the classfile name

https://github.com/lampepfl/dotty/blob/f29eea79bb1bae6849dd9842c131b2eb1c1d1cb8/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala#L204-L205

and to do otherwise would likely require eagerly reading the classfile?

Can we just disallow @targetName on toplevel class/trait/object?

@smarter
Copy link
Member

smarter commented Apr 28, 2022

Hmm, this also breaks the convention that there's a Foo.tasty matching Foo.class, so I now agree that we should just disallow this.

@smarter smarter removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Apr 28, 2022
@smarter smarter added this to the 3.2.0-RC1 milestone Apr 28, 2022
@Kordyjan Kordyjan modified the milestones: 3.2.0-RC1, 3.2.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants