Skip to content

Commit 8dc68c3

Browse files
committed
Handle named context bounds in poly function context bound desugaring
1 parent a76470f commit 8dc68c3

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,15 +1230,19 @@ object desugar {
12301230
case td @ TypeDef(name, cb @ ContextBounds(bounds, ctxBounds)) =>
12311231
TypeDef(name, ContextBounds(bounds, List.empty))
12321232
}
1233-
var idx = -1
1233+
var idx = 0
12341234
val collecedContextBounds = tparams.collect {
12351235
case td @ TypeDef(name, cb @ ContextBounds(bounds, ctxBounds)) if ctxBounds.nonEmpty =>
12361236
// TOOD(kπ) Should we handle non empty normal bounds here?
12371237
name -> ctxBounds
12381238
}.flatMap { case (name, ctxBounds) =>
12391239
ctxBounds.map { ctxBound =>
12401240
idx = idx + 1
1241-
makeSyntheticParameter(idx, ctxBound).withAddedFlags(Given)
1241+
ctxBound match
1242+
case ContextBoundTypeTree(_, _, ownName) =>
1243+
ValDef(ownName, ctxBound, EmptyTree).withFlags(TermParam | Given)
1244+
case _ =>
1245+
makeSyntheticParameter(idx, ctxBound).withAddedFlags(Given)
12421246
}
12431247
}
12441248
val contextFunctionResult =

tests/pos/contextbounds-for-poly-functions.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ trait Ord[X]:
77

88
val less1 = [X: Ord] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0
99

10+
val less2 = [X: Ord as ord] => (x: X, y: X) => ord.compare(x, y) < 0
11+
1012
// type Comparer = [X: Ord] => (x: X, y: X) => Boolean
11-
// val less2: Comparer = [X: Ord as ord] => (x: X, y: X) => ord.compare(x, y) < 0
13+
// val less3: Comparer = [X: Ord as ord] => (x: X, y: X) => ord.compare(x, y) < 0
1214

1315
// type Cmp[X] = (x: X, y: X) => Boolean
1416
// type Comparer2 = [X: Ord] => Cmp[X]
15-
// val less3: Comparer2 = [X: Ord] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0
17+
// val less4: Comparer2 = [X: Ord] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0

0 commit comments

Comments
 (0)