Skip to content

Commit 51b248d

Browse files
committed
Fix #2979: Handle instantiated typeparams when approximating
During interpolation a type parameter might become instantiated. This is now handled correctly.
1 parent 9a26f67 commit 51b248d

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,15 @@ trait ConstraintHandling {
227227
}
228228
}
229229
}
230-
if (constraint.contains(param)) {
231-
val bound = if (fromBelow) constraint.fullLowerBound(param) else constraint.fullUpperBound(param)
232-
val inst = avoidParam(bound)
233-
typr.println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}")
234-
inst
235-
}
236-
else {
237-
assert(ctx.mode.is(Mode.Interactive))
238-
UnspecifiedErrorType
230+
constraint.entry(param) match {
231+
case _: TypeBounds =>
232+
val bound = if (fromBelow) constraint.fullLowerBound(param) else constraint.fullUpperBound(param)
233+
val inst = avoidParam(bound)
234+
typr.println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}")
235+
inst
236+
case inst =>
237+
assert(inst.exists, i"param = $param\n constraint = $constraint")
238+
inst
239239
}
240240
}
241241

tests/neg/i2979.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Main {
2+
Map(
3+
"a" -> Unknown(), // error
4+
"b" -> Unknown() // error
5+
)
6+
}

0 commit comments

Comments
 (0)