-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Override method with implicit methods. #2000
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
That's intentional. Implicit methods should not be able to override normals methods. ImplicitFunctionN is an exception. it should not undergo this check. |
And, I am not sure at all we want to make implicit function classes extensible. Make them final instead? |
I believe that treating the Here's an example in scalac that lets you override without the scala> class C[A] { def foo(a: A) = "c" }
class D extends C[String] { def foo(implicit s: String) = "d" }
(new D(): C[String]).foo("")
defined class C
defined class D
res3: String = d A related bug: SI-3653, was fixed by removing the Wouldn't it be better to treat the method types as equivalent, and report the mismatched |
Another manifestation: scala> class C[A] { final def foo(a: A) = "c" }; class D extends C[String] { def foo(implicit s: String) = "d" }; new D
java.lang.VerifyError: class D overrides final method foo.(Ljava/lang/Object;)Ljava/lang/String;
at java.lang.ClassLoader.defineClass1(Native Method) |
Making the methods equivalent would also fix a similar issue with overloading #2002. I will also try to see if it is possible to decouple |
The same hole exists for multiple parameter lists: scala> class C[A] { final def foo(a: A)(b: A) = "c" }; class D extends C[String] { def foo(s: String, t: String) = "d" }; new D
java.lang.VerifyError: class D overrides final method foo.(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/String;
at java.lang.ClassLoader.defineClass1(Native Method) |
This is another override that is currently valid, but should not. class A {
def foo(implicit i: Int): Int = i + i
}
class B extends A {
override def foo(i: Int): Int = i
} |
This removes an illegal method override mentioned in scala#2000.
I don't see why last one shouldn't be valid. Both methods have the same signature and thus one overrides another. I agree with @retronym that it would be better if |
The issue is not that it is not a valid override, in fact in this case it should identify it as a valid override. But we would need another check that forces implicit method to be overriden by implicit methods and non implicit method by non implicit methods. |
It is worth noting that we already report modifier mismatches in refchecks, in the same manner as I'm proposing above, for access modifiers:
|
Trying out a scalac implementation in scala/scala#5722 |
I agree that we should catch this in rechecks. |
This removes an illegal method override mentioned in scala#2000.
This removes an illegal method override mentioned in scala#2000.
Fix #2000: Make implicit and non-implicit functions incomparable
With this change, (implicit x: C): D <: (x: C): D but not the other way around. This affects subtyping of dependent implicit function types. Now: (implicit x: C) => D <: (x: C) => D See also scala#2000. As a second change, prevent crashing on type mismatch errors involving dependent implicit function types.
With this change, (implicit x: C): D <: (x: C): D but not the other way around. This affects subtyping of dependent implicit function types. Now: (implicit x: C) => D <: (x: C) => D See also scala#2000. As a second change, prevent crashing on type mismatch errors involving dependent implicit function types.
I am still reluctant to allow arbitrary implicit/non-implicit overrides but #3692 requires that an implicit method can match a non-implicit one, since otherwise
even tough
That does not seem to be reasonable. It is changed in #3704. |
Currently we are unable to override a method with an implicit method as the implicit method is not a subtype of the plain method. This is in used in the definitions of the synthetic symbols for
ImplicitFunctionN
but it does not work properly. I found the following two issuesImplicitFunctionN.apply
without theimplicit
. Making the function class implementingImplicitFunctionN
behave as aFunctionN
.The text was updated successfully, but these errors were encountered: