You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@main deftest:Unit= {
classFooclassBarextendsFootraitS[-A] {
typeT>:A
}
traitPFooextendsS[Foo]
traitPBarextendsS[Bar] {
overridetypeT=Bar
}
classPFooBarextendsPBarwithPFoo {
overridetypeT>:Bar
}
defpatmat[A](s: S[A]): s.T= s match {
casep: (PFoo& s.type) => (newFoo): p.T
}
// ClassCastException: Foo cannot be cast to class Barvalx:Bar= patmat(newPFooBar:PBar)
}
Output
Click to expand
java.lang.ClassCastException: main$package$Foo$1 cannot be cast to main$package$Bar$1
at main$package$.test(main.scala:21)
at test.main(main.scala:1)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sbt.Run.invokeMain(Run.scala:115)
at sbt.Run.execute$1(Run.scala:79)
at sbt.Run.$anonfun$runWithLoader$4(Run.scala:92)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:10)
at sbt.TrapExit$App.run(TrapExit.scala:257)
at java.lang.Thread.run(Thread.java:748)
Expectation
The code should be rejected, but to me, it is not clear where the problem lies. I think the issue is allowing PBar to assign Bar to T. I also find it rather strange that PFooBar#T is allowed to be a supertype of Bar, it should be rejected and we should instead have PFooBar#T >: Bar | Foo (= Foo)
The text was updated successfully, but these errors were encountered:
error: incompatible type in overriding
type T >: Foo (defined in trait S)
with override type T = Bar (defined in trait PBar);
found : Bar
required: >: Foo
odersky
added a commit
to dotty-staging/dotty
that referenced
this issue
Jan 15, 2021
In a situation like
```
class A { type T = B }
class B extends A { override type T }
```
We only checked that `T` in `A` correctly overrides `T` in `B`, since `T` in `A`
is taken to be the overriding member, since it is abstract. But we also have to check
the reverse.
This replaces a more specialized treatment where we checked that final members
in `Object` could not be overridden by abstract members in traits. I removed a bunch
of tests that all tested variations of that other check, and changed the check
file for one representative.
Fixesscala#11130
Uh oh!
There was an error while loading. Please reload this page.
Minimized code
Output
Click to expand
Expectation
The code should be rejected, but to me, it is not clear where the problem lies. I think the issue is allowing
PBar
to assignBar
toT
. I also find it rather strange thatPFooBar#T
is allowed to be a supertype ofBar
, it should be rejected and we should instead havePFooBar#T >: Bar | Foo (= Foo)
The text was updated successfully, but these errors were encountered: