Skip to content

name hashing does not track names of synthetic symbols and names from synthetic methods #2537

@eed3si9n

Description

@eed3si9n

gkossakowski#9

As discussed here the current strategy for extracting used names might miss synthetic names for case classes like copy, apply, unapply, etc.

This ticket is a reminder for me to investigate this issue further. Both for members of case classes and other synthetic members.

steps

// A.scala
case class A(a: Int)
// B.scala
class B { def test(a: A) = a.copy() }

// > compile

// A.scala
case class A(a: Int) { private def copy = ??? }

// > compile
// [info] Compiling 1 Scala source to /Users/jason/code/scratch1/target/scala-2.11/classes...
// [success]

// > ;clean;compile
// ...
// [info] Compiling 2 Scala sources to /Users/jason/code/scratch1/target/scala-2.11/classes...
// [error] /Users/jason/code/scratch1/src/main/scala/B.scala:2: method copy in class A cannot be accessed in A
// [error]   def test(a: A) = a.copy()
// [error]                      ^

problem

Name hashing under compiles.

expectation

Changes are detected.

notes

isSynthetic is intentionally omitted.

 private def eligibleAsUsedName(symbol: Symbol): Boolean = {
    def emptyName(name: Name): Boolean = name match {
      case nme.EMPTY | nme.EMPTY_PACKAGE_NAME | tpnme.EMPTY | tpnme.EMPTY_PACKAGE_NAME => true
      case _ => false
    }

    (symbol != NoSymbol) &&
      !symbol.isSynthetic &&
      !emptyName(symbol.name)
  }

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