Skip to content

Commit f4ad535

Browse files
committed
fix scala#2051: allow override T with => T or ()T
1 parent 921f8bf commit f4ad535

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,8 @@ object Types {
727727

728728
/** Is this type a legal type for a member that overrides another
729729
* member of type `that`? This is the same as `<:<`, except that
730-
* the types ()T and => T are identified, and T is seen as overriding
731-
* either type.
730+
* the types `()T`, `=> T` and `T` are seen as overriding
731+
* each other.
732732
*/
733733
final def overrides(that: Type)(implicit ctx: Context) = {
734734
def result(tp: Type): Type = tp match {
@@ -737,7 +737,8 @@ object Types {
737737
}
738738
(this frozen_<:< that) || {
739739
val rthat = result(that)
740-
(rthat ne that) && (result(this) frozen_<:< rthat)
740+
val rthis = result(this)
741+
(rthat.ne(that) || rthis.ne(this)) && (rthis frozen_<:< rthat)
741742
}
742743
}
743744

tests/pos/i2051.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class A[T](val x:T)
2+
class B[T](override val x:T) extends A[T](x)

0 commit comments

Comments
 (0)