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

sams could play nicer with overloading #8310

Closed
scabug opened this issue Feb 18, 2014 · 2 comments
Closed

sams could play nicer with overloading #8310

scabug opened this issue Feb 18, 2014 · 2 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Feb 18, 2014

import java.util._

object TestOkay {
  def sort(x: java.util.Comparator[_ >: String]) = ()
  sort((a: String, b: String) => a.compareToIgnoreCase(b))
}

object TestOkay2 {
  def sort[T](x: java.util.Comparator[_ >: T]) = ()
  sort((a: String, b: String) => a.compareToIgnoreCase(b))
}


object TestOkay3 {
  def sort[T](xs: Option[T], x: java.util.Comparator[_ >: T]) = ()
  sort(Some(""), (a: String, b: String) => a.compareToIgnoreCase(b))
}

object TestKoOverloaded {
  def sort[T](xs: Option[T]) = ()
  def sort[T](xs: Option[T], x: java.util.Comparator[_ >: T]) = ()
  sort(Some(""), (a: String, b: String) => a.compareToIgnoreCase(b))
}

Overloading resolution type checks the function literal without an expected type, and then discards the overloaded alternative as Function1 doesn't conform to Comparator.

Java can handle this, presumably because it filters overloaded alternatives based on arity first (we filter them based on isApplicable, which might tuple args, add defaults, etc).

Maybe this will wind up as a wont-fix, but we should document the limitation in the SAM SIP for 2.12.

@scabug
Copy link
Author

scabug commented Feb 18, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8310?orig=1
Reporter: @retronym
Affected Versions: 2.11.0-M8

@scabug
Copy link
Author

scabug commented Nov 6, 2014

@adriaanm said:
scala/scala#4101

@scabug scabug closed this as completed Nov 10, 2014
@scabug scabug added this to the 2.11.5 milestone Apr 7, 2017
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