-
Notifications
You must be signed in to change notification settings - Fork 21
implicit search does not account for singleton types #3964
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-3964?orig=1 |
@paulp said:
Result of 1: "implicit def f(x: Foo.type)" will convert object Foo. Also included are some clarity-enhnancing renamings and refactorings. Closes #2693, #3964. Review by moors, who wrote most of this patch |
@Blaisorblade said: scala> val a: String = ""
a: String = ""
scala> case class Marked(a: String)
defined class Marked
scala> implicit def foo(b: String): Marked = Marked(b)
warning: there were 1 feature warnings; re-run with -feature for details
foo: (b: String)Marked
scala> def ctx(c: Marked) = c
ctx: (c: Marked)Marked
scala> ctx(a)
res0: Marked = Marked()
scala> implicit def bar(b: a.type): Marked = null
warning: there were 1 feature warnings; re-run with -feature for details
bar: (b: a.type)Marked
scala> ctx(a) //This is expected to return null because the implicit conversion bar should be applied; conversions however are not applied in the right order.
res1: Marked = Marked()
scala> ctx(bar(a)) //This expansion should be considered (and make the code ambiguous) or applied (because it is more specific).
res2: Marked = null
scala> ctx(a: a.type)
res3: Marked = null |
@paulp said: final val a = "" |
@Blaisorblade said: However, I'm confused by the use of 'final' for this, since final in Java marks immutable values and Scala doesn't change so much the meaning of existing syntax, hence it seems redundant with val. I just learned, though, that 'final val' has a specific meaning already in Scala 2.9 - which does not make it less confusing, just already existing. |
@paulp said: |
One of those issues I've been sitting on forever and talking to adriaan makes me realize that maybe everyone else doesn't cry for half an hour every morning about it and that the mere act of opening a ticket might make a difference.
And so! I believe this code should work:
And were it to work, I would also hope for this to work, as it does for the analogous case for normal classes:
I am familiar with #1208 and the fact that singleton types will not sing and dance with wild abandon. I'm hoping this situation doesn't fall under the general umbrella both because it would be super useful, and because it would mean implicit search doesn't use normal function application rules, as visible here:
The text was updated successfully, but these errors were encountered: