Skip to content

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

Closed
@smarter

Description

@smarter

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions