File tree 3 files changed +28
-1
lines changed
compiler/src/dotty/tools/dotc/typer
3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -3038,7 +3038,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3038
3038
body
3039
3039
3040
3040
/** Implement givens that were declared with a `deferred` rhs.
3041
- * The a given value matching the declared type is searched in a
3041
+ * The given value matching the declared type is searched in a
3042
3042
* context directly enclosing the current class, in which all given
3043
3043
* parameters of the current class are also defined.
3044
3044
*/
@@ -3055,6 +3055,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3055
3055
false
3056
3056
else true
3057
3057
3058
+ def willBeimplementedInParentClass (m : TermRef ) =
3059
+ val superCls = cls.superClass
3060
+ superCls.exists && superCls.asClass.baseClasses.contains(m.symbol.owner)
3061
+
3058
3062
def givenImpl (mbr : TermRef ): ValDef =
3059
3063
val dcl = mbr.symbol
3060
3064
val target = dcl.info.asSeenFrom(cls.thisType, dcl.owner)
@@ -3084,6 +3088,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3084
3088
cls.thisType.implicitMembers
3085
3089
// .showing(i"impl def givens for $cls/$result")
3086
3090
.filter(_.symbol.isAllOf(DeferredGivenFlags , butNot = Param ))
3091
+ .filter(! willBeimplementedInParentClass(_)) // only implement the given in the topmost class
3087
3092
// .showing(i"impl def filtered givens for $cls/$result")
3088
3093
.filter(isGivenValue)
3089
3094
.map(givenImpl)
Original file line number Diff line number Diff line change
1
+ //> using options -source:future -language:experimental.modularity
2
+
3
+ class MySortedSet [T : Ord ] extends SortedSet [T ]
4
+
5
+ trait Ord [T ]
6
+
7
+ trait Sorted [T ] extends ParentOfSorted [T ]
8
+
9
+ trait ParentOfSorted [T ]:
10
+ given Ord [T ] as ord = compiletime.deferred
11
+
12
+ class SortedSet [T : Ord ] extends Sorted [T ]
Original file line number Diff line number Diff line change
1
+ //> using options -source:future -language:experimental.modularity
2
+
3
+ class MySortedSet [T : Ord ] extends SortedSet [T ]
4
+
5
+ trait Ord [T ]
6
+
7
+ trait Sorted [T ]:
8
+ given Ord [T ] as ord = compiletime.deferred
9
+
10
+ class SortedSet [T : Ord ] extends Sorted [T ]
You can’t perform that action at this time.
0 commit comments