Skip to content

Java Generic Signature for nested refinements imprecise #10543

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

Open
retronym opened this issue Oct 9, 2017 · 0 comments
Open

Java Generic Signature for nested refinements imprecise #10543

retronym opened this issue Oct 9, 2017 · 0 comments
Milestone

Comments

@retronym
Copy link
Member

retronym commented Oct 9, 2017

object Test {
  def main(args: Array[String]) {
    println(classOf[Foo[_]].getTypeParameters.apply(0).getBounds)
  }
}

class C1 { def c1 = 0 }
trait T1 { def t1: Int }
trait T2 { def t2: Int }
class Foo[T <: (C1 with T1) with T2]// Note the parentheses

Prints: class C1, interface T2

Could we include T1 in the signature, too?

Discovered during porting of our implementation to dotty: scala/scala3#3234 (comment)

Fix is probably as simple as adding a recursive case to:

  private def hiBounds(bounds: TypeBounds): List[Type] = bounds.hi.dealiasWiden match {
    case RefinedType(parents, _) => parents map (_.dealiasWiden)
    case tp                      => tp :: Nil
  }

(Or using the existing flattening in RefinedType.normalize)

We need to be careful when changing this that we maintain the invariant that the erased type conforms to the generic type.

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

2 participants