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

targetName allows shadowing public member with private member, leading to IllegalAccessError at runtime #18244

Closed
smarter opened this issue Jul 18, 2023 · 0 comments · Fixed by #18361

Comments

@smarter
Copy link
Member

smarter commented Jul 18, 2023

Compiler version

3.3.0

Minimized code

import scala.annotation.*

class A:
  def foo: Int = 1
class B extends A:
  @targetName("foo") private[this] def bla: Int = 2

@main def Test =
  val b = new B
  println(b.foo)

Output

Exception in thread "main" java.lang.IllegalAccessError: tried to access method B.foo()I from class targetName$package$
        at targetName$package$.Test(targetName.scala:10)
        at Test.main(targetName.scala:8)

Expectation

A compilation error, similar to what one gets when trying to define a private def that shadows a public one.

@smarter smarter added itype:bug itype:crash area:refchecks stat:needs triage Every issue needs to have an "area" and "itype" label and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 18, 2023
odersky added a commit to dotty-staging/dotty that referenced this issue Aug 8, 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.

1 participant