Skip to content

private path-dependent type can be widened automatically if referred by non-private methods #22264

Open
@tribbloid

Description

@tribbloid

Compiler version

3.6.2

Minimized code

package com.tribbloids.spike.dotty

object PrivateEscapingScope {

  trait T1 {

    object R1 extends Product
    type R1 = R1.type
  }

  trait K1 {
    private lazy val t1: T1 = new T1 {}

    def r1 = t1.R1 // the only difference with K2 is lazy caching

    /**
      * non-private method r1 in trait K1 refers to private lazy value t1 in its type signature => K1.this.t1.R1.type
      * def r1 = t1.R1 // the only difference with K2 is lazy caching
      */
  }

  type T1R1 = T1#R1

  trait K1_2 {
    private lazy val t1: T1 = new T1 {}

    def r1: T1#R1 = t1.R1

    /**
      * Found: K1_2.this.t1.R1.type
      *
      * Required: com.tribbloids.spike.dotty.PrivateEscapingScope.T1#R1
      *
      * Explanation \===========
      *
      * Tree: this.t1.R1 I tried to show that K1_2.this.t1.R1.type conforms to
      * com.tribbloids.spike.dotty.PrivateEscapingScope.T1#R1 but none of the attempts shown below succeeded:
      *
      * \==> K1_2.this.t1.R1.type <: com.tribbloids.spike.dotty.PrivateEscapingScope.T1#R1 CachedTermRef CachedTypeRef
      * \==> object K1_2.this.t1.R1 <: com.tribbloids.spike.dotty.PrivateEscapingScope.T1#R1 CachedTypeRef CachedTypeRef
      * \= false
      *
      * The tests were made under the empty constraint
      *
      * def r1: T1#R1 = t1.R1
      */
  }

  trait K1_3 {
    private lazy val t1: T1 = new T1 {}

    def r1: Product = t1.R1 // success: explicitly widen to Product
  }

  trait K2 {
    private def t1: T1 = new T1 {}

    def r1 = t1.R1 // success: widen to T1#R1
  }
}

Output

both K1 and K1_2 fail to compile, because K1.t1 has a path but K2.t1 doesn't

K1_2 in addition displayed a strange error message, this may be caused by the simple type projection T1#R1, which is not DOT logic but legal in Scala 3

Expectation

Both T1 and T1_2 should compile successfully, since t1 is a private path, r1 should automatically be widen to T1#R1 or Product

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