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

Path dependent type is lost when aliases type parameter and is used in hof #9004

Open
scabug opened this issue Nov 25, 2014 · 7 comments
Open
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) minimized should compile typer
Milestone

Comments

@scabug
Copy link

scabug commented Nov 25, 2014

object Main extends App {
  trait A[RR] { type R <: RR; def r: R }
  def f1(a: A[_]): a.R = a.r
  def f(a: A[_]): Option[a.R] = Some(1).map(_ => a.r)
 
  trait AA[RR] { type R = RR; def r: R }
  def f1(a: AA[_]): a.R = a.r
  def f(a: AA[_]): Option[a.R] = Some(1).map(_ => a.r)
 /**
[error]  found   : Int => Any
[error]  required: Int => a.R
[error]     (which expands to)  Int => _$4
[error]   def f(a: AA[_]): Option[a.R] = Some(1).map(_ => a.r)
**/
}
@scabug
Copy link
Author

scabug commented Nov 25, 2014

Imported From: https://issues.scala-lang.org/browse/SI-9004?orig=1
Reporter: @OlegYch
Affected Versions: 2.10.4, 2.11.4
See #6904

@scabug
Copy link
Author

scabug commented Nov 27, 2014

@retronym said:
Here's another encoding which works:

def f[R](a: AA[R]): Option[a.R] = Some(1).map(_ => a.r)

@scabug
Copy link
Author

scabug commented Nov 27, 2014

@retronym said:

object Main {
  trait AA[RR] { type R = RR; def r: R }

  def test1(a: AA[B] forSome { type B }) = {
    val f = () => a.r
    // The tree a.r is given the type `a.R` which normalizes
    // to B', where B' is a distinct symbol ("captured existential skolem")
    // to substitute for the reference to an existential skolem of B.
    //
    // inference of the result type of the function computes the
    // packed type of tree `a.r` to make sure that terms and types
    // local to the body of the function don't leak into its result
    // type. The captured existential skolem is considered to be local
    // so it is abstracted to its upper bound, Any.
    f: (() => a.R)

    // The workaround is to annotate the function type, rather than
    // relying in inference.
    val g: (() => a.R) () => a.r

    ()
  }
  // typer debug trace: http://rawgit.com/retronym/d5aeaf8e0a4a2e6eef4b/raw/out.html
}

@scabug
Copy link
Author

scabug commented Nov 27, 2014

@retronym said:
I think I might have a solution: https://github.com/retronym/scala/tree/ticket/9004

I'll see if that change is at odds with the test suite. Assuming it is sound, we'll have to hide it behind -Xsource:2.12.

@scabug
Copy link
Author

scabug commented Nov 28, 2014

@retronym said:
:*(

Two failing tests on that branch:

test/partest \
  /Users/jason/code/scala3/test/files/pos/t8023.scala \
  /Users/jason/code/scala3/test/files/neg/t5378.scala

@scabug
Copy link
Author

scabug commented Jan 27, 2015

@retronym said (edited on Jan 27, 2015 2:52:42 AM UTC):
Another test case that crashes under my proposed fix:

object Test {
  def foo1[A1] = new { private type A2 = A1 ; def bar: A2 = ??? }
  // def foo2[A1] = new {         type A2 = A1 ; def bar: A2 = ??? }
 
  def f1: Int = foo1[Int].bar
  // def f2: Int = foo2[Int].bar
}

@scabug
Copy link
Author

scabug commented Jan 27, 2015

@retronym said:
#6904 seems related to the problem with dealiasing in packedType.

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@pabloazul pabloazul added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Nov 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) minimized should compile typer
Projects
None yet
Development

No branches or pull requests

4 participants