Skip to content

Commit 4060cf2

Browse files
committed
Handle named context bounds in poly function context bound desugaring
1 parent d653f5a commit 4060cf2

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
@@ -1218,15 +1218,19 @@ object desugar {
12181218
case td @ TypeDef(name, cb @ ContextBounds(bounds, ctxBounds)) =>
12191219
TypeDef(name, ContextBounds(bounds, List.empty))
12201220
}
1221-
var idx = -1
1221+
var idx = 0
12221222
val collecedContextBounds = tparams.collect {
12231223
case td @ TypeDef(name, cb @ ContextBounds(bounds, ctxBounds)) if ctxBounds.nonEmpty =>
12241224
// TOOD(kπ) Should we handle non empty normal bounds here?
12251225
name -> ctxBounds
12261226
}.flatMap { case (name, ctxBounds) =>
12271227
ctxBounds.map { ctxBound =>
12281228
idx = idx + 1
1229-
makeSyntheticParameter(idx, ctxBound).withAddedFlags(Given)
1229+
ctxBound match
1230+
case ContextBoundTypeTree(_, _, ownName) =>
1231+
ValDef(ownName, ctxBound, EmptyTree).withFlags(TermParam | Given)
1232+
case _ =>
1233+
makeSyntheticParameter(idx, ctxBound).withAddedFlags(Given)
12301234
}
12311235
}
12321236
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)