Skip to content

Inference of inaccessible types #4228

Open
@Blaisorblade

Description

@Blaisorblade

Type inference sometimes produces inaccessible types, but should widen then to visible ones. An example from 2012: https://groups.google.com/d/msg/scala-internals/0j8laVNTQsI/B6fu1e4KJ2sJ

package a {
  private[a] trait Impl { def f = 5 }
  class Vis1 extends Object with Impl
  class Vis2 extends Object with Impl

  object Vis {
    def f = new Vis1
    def g = new Vis2
    def lub = List(f, g)  // this should be (and is) a List[Impl]
  }
}
package b {
  object Elsewhere {
    import a.Vis._
    def lub = List(f, g) // this should not be (but is) a List[a.Impl]
  }
}

Running the REPL with the output confirms the issue is still there:

> repl -classpath out
[...]
scala> a.Vis.lub
val res0: List[a.Impl] = List(a.Vis1@67e28be3, a.Vis2@e344ad3)
scala> b.Elsewhere.lub
val res1: List[a.Impl] = List(a.Vis1@63716833, a.Vis2@573284a5)

(BTW, the other example in that email is instead fixed, arguably better in Dotty than in Scalac):

scala> def f = { trait A ; trait B extends A ; trait C extends B ; new C { } }; lazy val g = f
def f: Object
val g: Object = <lazy>

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