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 @@ -3019,7 +3019,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3019
3019
body
3020
3020
3021
3021
/** Implement givens that were declared with a `deferred` rhs.
3022
- * The a given value matching the declared type is searched in a
3022
+ * The given value matching the declared type is searched in a
3023
3023
* context directly enclosing the current class, in which all given
3024
3024
* parameters of the current class are also defined.
3025
3025
*/
@@ -3036,6 +3036,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3036
3036
false
3037
3037
else true
3038
3038
3039
+ def willBeimplementedInParentClass (m : TermRef ) =
3040
+ val superCls = cls.superClass
3041
+ superCls.exists && superCls.asClass.baseClasses.contains(m.symbol.owner)
3042
+
3039
3043
def givenImpl (mbr : TermRef ): ValDef =
3040
3044
val dcl = mbr.symbol
3041
3045
val target = dcl.info.asSeenFrom(cls.thisType, dcl.owner)
@@ -3065,6 +3069,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3065
3069
cls.thisType.implicitMembers
3066
3070
// .showing(i"impl def givens for $cls/$result")
3067
3071
.filter(_.symbol.isAllOf(DeferredGivenFlags , butNot = Param ))
3072
+ .filter(! willBeimplementedInParentClass(_)) // only implement the given in the topmost class
3068
3073
// .showing(i"impl def filtered givens for $cls/$result")
3069
3074
.filter(isGivenValue)
3070
3075
.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