Skip to content

Commit 57f53d0

Browse files
committed
Better types for class type parameters
If we see a class type parameter that has a wildcard argument, we now intersect the original info of the class type parameter and the argument. Previously we replaced the class type parameter info with the argument info, but that might lose information. Fixes #15940
1 parent bf03086 commit 57f53d0

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ object Denotations {
11201120
then this
11211121
else if symbol.isAllOf(ClassTypeParam) then
11221122
val arg = symbol.typeRef.argForParam(pre, widenAbstract = true)
1123-
if arg.exists then derivedSingleDenotation(symbol, arg.bounds, pre)
1123+
if arg.exists then derivedSingleDenotation(symbol, symbol.info.bounds & arg.bounds, pre)
11241124
else derived(symbol.info)
11251125
else derived(symbol.info)
11261126
}

tests/pos/i15940.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
object Ops:
2+
implicit class EitherSeqOps[E, T](private val seq: Seq[Either[E, T]]) extends AnyVal:
3+
def sequence: Either[::[E], Seq[T]] = ???
4+
5+
trait BuildException
6+
case class CompositeBuildException(ex: ::[BuildException]) extends BuildException
7+
8+
trait ActionableDiagnostic
9+
trait ActionableHandler[A <: ActionableDiagnostic]:
10+
def exec: Either[BuildException, Seq[A]]
11+
12+
import Ops._
13+
14+
val test: Either[BuildException, Seq[ActionableDiagnostic]] =
15+
// Can be replaced with Seq[Either[BuildException, Seq[ _ <: ActionableDiagnostic]]] , but current version matches better type of missing implicit
16+
Seq.empty[ActionableHandler[_]].map(_.exec)
17+
.sequence
18+
.left.map(_.head)
19+
.map(_.flatten) // error

0 commit comments

Comments
 (0)