-
Notifications
You must be signed in to change notification settings - Fork 21
Fail to resolve overloaded method via implicit class with same name and different signature #10206
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-10206?orig=1 |
@adriaanm said: |
@adriaanm said (edited by @SethTisue on Feb 23, 2017 10:32:28 PM UTC): pt match {
case Function1(_, out) =>
// must inline to avoid capturing result
def prohibit(sym: Symbol) = (sym.tpe <:< out) && { // BUG: when looking for implicit conversion to `?{def clone: ?}`, this triggers because AnyRef has that method
maybeInvalidConversionError(s"the result type of an implicit conversion must be more specific than ${sym.name}")
true
}
if (prohibit(AnyRefClass) || (settings.isScala211 && prohibit(AnyValClass)))
result = SearchFailure
case _ => false
} |
@adriaanm said: |
Yuval Itzchakov (Yuval.Itzchakov) said (edited on Feb 24, 2017 8:42:41 AM UTC): Would you mind elaborating how/why a structural type supertyping AnyRef is created here? |
Jasper-M said (edited on Feb 24, 2017 9:44:52 AM UTC): scala> class Foo { def apply(a: Int, b: Int) = (a,b) }
defined class Foo
scala> implicit class IntFoo(i: Int) { def foo = new Foo }
defined class IntFoo
scala> 1.foo(2,3)
res1: (Int, Int) = (2,3) So when you call
has to be considered. And that is a supertype of {{AnyRef}}. |
Yuval Itzchakov (Yuval.Itzchakov) said (edited on Feb 24, 2017 10:42:57 AM UTC): When you write 1.foo(2,3) Why does an implicit conversion to a structural have to be considered? I would expect that an implicit conversion on To add to the question, even if there is a structural type to has to be looked up, why is it a supertype of |
Jasper-M said: Int => ?{def foo: ?} because it doesn't know anything about the required result type other than that it should have a method called Now aside of that, I think the compiler uses some extra internal mechanisms other than pure basic userfacing implicit search, because scala> implicitly[AnyRef <:< Any{def clone: Any}]
<console>:8: error: Cannot prove that AnyRef <:< Any{def clone: Any}.
implicitly[AnyRef <:< Any{def clone: Any}]
^
scala> implicitly[AnyRef <:< Any{def clone(): Any}]
res1: <:<[AnyRef,Any{def clone(): Any}] = <function1> |
Yuval Itzchakov (Yuval.Itzchakov) said (edited on Feb 24, 2017 3:55:36 PM UTC): Just to clear my mind, when we say "structural type", we're talking about some structure of a type and not explicitly about the Scala feature called structural types, right? We just need a way to describe a shape of a type we don't know yet. Regarding your example in the code, what is that trying to convey? Not sure I follow. I would imagine the first one doesn't work is it doesn't match the structure of |
As per this Stackoverflow question, following fails to compile:
Perhaps indirectly related to SI-6760 but overloaded method had different signature than
Object.clone
.This does compile under 2.10.6. Biggest difference I see in the type tree is that 2.10.6 tried to cook the method parameters while 2.11.8 doesn't:
2.11.8:
2.10.6:
The text was updated successfully, but these errors were encountered: