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

Scalac cannot inference existential type #6604

Closed
scabug opened this issue Nov 2, 2012 · 5 comments
Closed

Scalac cannot inference existential type #6604

scabug opened this issue Nov 2, 2012 · 5 comments

Comments

@scabug
Copy link

scabug commented Nov 2, 2012

scala> scala.util.control.Exception.catching(classOf[ClassNotFoundException]).opt(Class.forName(""))
<console>:8: error: type mismatch;
 found   : java.lang.Class[_]
 required: java.lang.Class[?0(in value res0)] where type ?0(in value res0)
Note: Any >: ?0, but Java-defined class Class is invariant in type T.
You may wish to investigate a wildcard type such as `_ >: ?0`. (SLS 3.2.10)
              scala.util.control.Exception.catching(classOf[ClassNotFoundException]).opt(Class.forName(""))
                                                                                                      ^

If I set the type parameter explicitly, it compiles:

scala> scala.util.control.Exception.catching(classOf[ClassNotFoundException]).opt[Class[_]](Class.forName(""))
res0: Option[java.lang.Class[_]] = None
@scabug
Copy link
Author

scabug commented Nov 2, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6604?orig=1
Reporter: @Atry
Affected Versions: 2.9.1, 2.9.2, 2.10.0-M1, 2.10.0-M2, 2.10.0-M3, 2.10.0-M4, 2.10.0-M5, 2.10.0-M6, 2.10.0-M7
See #5886

@scabug
Copy link
Author

scabug commented Nov 6, 2012

@adriaanm said:
I agree it would be nice to improve this. Sometimes you just have to add a type parameter, as type inference is limited. Avoid existential types whenever possible.

@scabug
Copy link
Author

scabug commented Jul 10, 2013

@adriaanm said:
Unassigning and rescheduling to M6 as previous deadline was missed.

@scabug scabug closed this as completed Dec 11, 2013
@scabug
Copy link
Author

scabug commented Feb 18, 2014

@retronym said:
Fixed along with #5886 in 01716c8d8553a027cb0583f90409652128286463 / v2.10.2~14

@scabug
Copy link
Author

scabug commented Feb 18, 2014

@retronym said:

scala-hash v2.10.2~15 -nc -e 'scala.util.control.Exception.catching(classOf[ClassNotFoundException]).opt(Class.forName(""))'
[info] downloading http://scala-webapps.epfl.ch/artifacts/70e2ead142f87ebd5f4c6859ce17c72fdff8bd3b/pack.tgz ...done.
[info] scala revision from 2013-05-15 15:59:12 -0700 downloaded to /Users/jason/usr/scala-v2.10.1-318-g70e2ead
/var/folders/s2/g6fgtpk52hl8njjvx8vyzr9r0000gn/T/scalacmd861028181716928737.scala:1: error: type mismatch;
 found   : Class[_]
 required: Class[?0(in value <local $anon>)] where type ?0(in value <local $anon>)
Note: Any >: ?0, but Java-defined class Class is invariant in type T.
You may wish to investigate a wildcard type such as `_ >: ?0`. (SLS 3.2.10)
scala.util.control.Exception.catching(classOf[ClassNotFoundException]).opt(Class.forName(""))
                                                                                        ^
  ~/code/scala scala-hash v2.10.2~14 -nc -e 'scala.util.control.Exception.catching(classOf[ClassNotFoundException]).opt(Class.forName(""))'

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