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

Type mismatch when existential type declared explicitly #6849

Closed
scabug opened this issue Dec 20, 2012 · 5 comments
Closed

Type mismatch when existential type declared explicitly #6849

scabug opened this issue Dec 20, 2012 · 5 comments

Comments

@scabug
Copy link

scabug commented Dec 20, 2012

Given code snippet does not compile when type of value v declared explicitly .

class O {
  class I
  val x = new O
  def v: x.I = ???
}

object Test extends App {
  val v: o.x.I forSome { val o: O } = (new O).v
}
ex_test.scala:10: error: type mismatch;
 found   : _1.x.I where val _1: O
 required: Test.o.x.I[]
  val v: o.x.I forSome { val o: O } = (new O).v
                                              ^
one error found

The code compiles with type alias or when type of v is inferred.

type T = o.x.I forSome { val o: O }
val v: T = (new O).v
@scabug
Copy link
Author

scabug commented Dec 20, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6849?orig=1
Reporter: Dmitry Bushev (4e6)
Affected Versions: 2.9.2, 2.10.0

@scabug
Copy link
Author

scabug commented Dec 20, 2012

@paulp said:
To my knowledge this is the expected behavior. Declaring the type as "o.x.I forSome { val o: O }" ties the type to some specific unknown "val o: O", and then you try to assign (new O).v to it, but this "new O" is not the specific unknown o. When you allow the type to be inferred, the compiler infers the type of the O you created, so they match.

I'm not 100% sure why the type alias works, but I offer as possibilities:

  1. It's a bug (and should also fail)
  2. Since it doesn't directly expose 'o' in its type it doesn't get handcuffed to "new O" in the same way

I'll leave it open for someone more confident about things.

@scabug
Copy link
Author

scabug commented Jan 7, 2013

@adriaanm said:
I agree with Paul's explanation and would vote for 1)

@scabug
Copy link
Author

scabug commented Jan 17, 2013

Lars Hupel (larsrh) said:
This looks related to http://thread.gmane.org/gmane.comp.lang.scala/28233/focus=28250:

scala> class X { object Y }
defined class X

scala> val x = new X
x: X = X <at> 4c769a3

scala> type XY = x.Y.type forSome { val x: X }
warning: there were 2 feature warnings; re-run with -feature for details
defined type alias XY

scala> val y1 = x.Y
y1: x.Y.type = X$Y$@14eee870

scala> val y2: XY = x.Y
y2: XY = X$Y$@14eee870

scala> val y2: (x.Y.type forSome { val x: X }) = x.Y
<console>:9: error: type mismatch;
 found   : x.Y.type
 required: x.Y.type forSome { val x: => X }
       val y2: (x.Y.type forSome { val x: X }) = x.Y
                                                   ^

@scabug
Copy link
Author

scabug commented Feb 1, 2014

@paulp said:
This started compiling somewhere between 2.10.0 and 2.10.1. I don't know whether it is progress or regress, but at least it is consistent with and without the type alias.

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@scala scala deleted a comment from scabug Aug 9, 2023
@SethTisue SethTisue modified the milestones: Backlog, 2.10.1 Aug 9, 2023
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