Skip to content
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

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

Open
tribbloid opened this issue Dec 24, 2024 · 0 comments

Comments

@tribbloid
Copy link

tribbloid commented Dec 24, 2024

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

@tribbloid tribbloid added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 24, 2024
@Gedochao Gedochao added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 30, 2024
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