Skip to content

Dotty fails to to infer type params for Java Stream API #801

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

Closed
DarkDimius opened this issue Sep 21, 2015 · 7 comments
Closed

Dotty fails to to infer type params for Java Stream API #801

DarkDimius opened this issue Sep 21, 2015 · 7 comments

Comments

@DarkDimius
Copy link
Contributor

object T{
  import java.util.ArrayList, java.util.stream.{Stream => JStream}
  new java.util.ArrayList[String]().stream.map(_.toInt).map(_.toString): JStream[String]
}
Streams.scala:3: error: toInt is not a member of <unknown instance of type java.util.function.Function[_ >: String, _ = Nothing]>
  .
java$util$function$Function$$T(_$1)
  new java.util.ArrayList[String]().stream.map(_.toInt).map(_.toString): JStream[String]
                                                 ^
Streams.scala:3: error: type mismatch:
 found   : <unknown instance of type java.util.function.Function[_ >: String, _ = Nothing]>
  .
java$util$function$Function$$T =>
  <unknown instance of type
    java.util.function.Function[_ >: String, _ = Nothing]
  >.java$util$function$Function$$R
 required: java.util.function.Function[_ >: String, _ <: Nothing']
  new java.util.ArrayList[String]().stream.map(_.toInt).map(_.toString): JStream[String]
                                               ^
Streams.scala:3: error: type mismatch:
 found   : String
 required: <unknown instance of type java.util.function.Function[_, _ <: String]>.
  java$util$function$Function$$R
  new java.util.ArrayList[String]().stream.map(_.toInt).map(_.toString): JStream[String]
                                                            ^
three errors found

see also https://groups.google.com/forum/#!msg/scala-language/Xy29pcRE04c/rwCvztHjsP8J for same issue for scalac

@adriaanm
Copy link
Contributor

Mostly related to mismatch between use site and definition site variance. How about inferring variance for Java interfaces? http://www.lirmm.fr/~ducour/Doc-objets/ECOOP2012/ECOOP/ecoop/509.pdf

@odersky
Copy link
Contributor

odersky commented Feb 5, 2016

@adriaanm What's the status of this issue for scalac?

@adriaanm
Copy link
Contributor

adriaanm commented Feb 5, 2016

I haven't made any progress on this. My original idea was to infer variance annotations for Java interfaces to feed that to type inference, so it can replace bounded wildcards by their upper/lower bounds depending on the variance position they occur in.

@odersky
Copy link
Contributor

odersky commented Feb 5, 2016

@adriaanm Thanks or the update! I was hoping I could lift some code from you guys there.

@adriaanm
Copy link
Contributor

adriaanm commented Feb 5, 2016

me too -- alas :)

@adriaanm
Copy link
Contributor

adriaanm commented Feb 5, 2016

(I did do some work this week on our SAM expansion: scala/scala#4945 -- ideally, I'd like to generalize Function ASTs to have any function/sam type, and emit the corresponding invokedynamic+LambdaMetaFactory calls in the back-end. Right now, we expand SAM types like PartialFunction ones during type checking)

@sjrd
Copy link
Member

sjrd commented Feb 5, 2016

I'd like to generalize Function ASTs to have any function/sam type, and emit the corresponding invokedynamic+LambdaMetaFactory calls in the back-end.

That would be awesome! We could get rid of all the awful hacks in Scala.js to recover anonymous functions from classes (at least, once we drop support for 2.10 and 2.11 ...)

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

5 participants