Skip to content

checkNoPrivateLeaks is done too late, code with inferred private types might break #1723

Closed
@smarter

Description

@smarter

checkNoPrivateLeaks replaces private types in signatures by dealiasing them if possible, but this is done in PostTyper which means that the following code does not compile (works in scalac):

class A {
  private type Foo = Int

  def foo: Foo = 1
}
class B extends A {
  foo
}
cannot take signature of => B.this.Foo
-- Error: ./try/1130x.scala ----------------------------------------------
7 |  foo
  |  ^^^
  |  cannot resolve reference to type B(B.this).Foo
  |  the classfile defining the type might be missing from the classpath

This is a big deal because inferred types might contain private types in perfectly innocent code:

class A {
  private val x: List[Int] = List(1)
  def foo = x.head // foo inferred type is this.x.scala$collection$immutable$List$$A
}

class B extends A {
  foo
}
cannot take signature of => B.this.x.scala$collection$immutable$List$$A
-- Error: ./try/i1130x.scala -------------------------------------------------------------------------------------------
7 |  foo
  |  ^^^
  |  cannot resolve reference to type B.this.x.type.scala$collection$immutable$List$$A
  |  the classfile defining the type might be missing from the classpath

I think we really need inference to avoid private types.

/cc @odersky

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions