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-dep types in case class constructor #7930

Closed
scabug opened this issue Oct 23, 2013 · 2 comments
Closed

Path-dep types in case class constructor #7930

scabug opened this issue Oct 23, 2013 · 2 comments
Assignees

Comments

@scabug
Copy link

scabug commented Oct 23, 2013

Given:

trait A { type B }

I don't see why this shouldn't compile:

case class DoesntWork(a: A)(b: a.type#B)

Instead I have to do the same thing manually a la:

class Blah(val a: A, rawb: Any) { def b = rawb.asInstanceOf[a.type#B] }
object Blah { def apply(a: A)(b: a.type#B) = new Blah(a, b) }

// Give it a try
val x = new A { type B=Int }
Blah(x)(123) // should work
Blah(x)("should fail")
@scabug
Copy link
Author

scabug commented Oct 23, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7930?orig=1
Reporter: David Barri (japgolly)
Affected Versions: 2.10.3
Duplicates #5712

@scabug scabug closed this as completed Oct 23, 2013
@scabug
Copy link
Author

scabug commented Oct 23, 2013

@retronym said:
Duplicate of #5712.

So far we only have dependent method types; constructors are not supported. It's surprisingly tricky to implement this unfortunately.

Here's a pattern to workaround:

scala> class A { class B }
defined class A

scala> object O1 extends A; object O2 extends A
defined module O1
defined module O2

scala> object Test { class Blah[AA <: A](val a: AA, b: AA#B); object Blah { def apply(a: A)(b: a.B) = new Blah[a.type](a, b) } }
defined module Test

scala> Test.Blah(O1)(new O1.B)
res2: Test.Blah[O1.type] = Test$Blah@54becf73

scala> Test.Blah(O1)(new O2.B)
<console>:15: error: type mismatch;
 found   : O2.B
 required: O1.B
              Test.Blah(O1)(new O2.B)
                            ^

Could I ask that you please check for duplicate tickets, either by searching JIRA or asking on the mailing list, before lodging new ones? Thanks.

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