Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better types for class type parameters #15951

Merged
merged 2 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,12 @@ object Denotations {
then this
else if symbol.isAllOf(ClassTypeParam) then
val arg = symbol.typeRef.argForParam(pre, widenAbstract = true)
if arg.exists then derivedSingleDenotation(symbol, arg.bounds, pre)
if arg.exists then
val newBounds =
if symbol.isCompleted && !symbol.info.containsLazyRefs
then symbol.info.bounds & arg.bounds
else arg.bounds
derivedSingleDenotation(symbol, newBounds, pre)
else derived(symbol.info)
else derived(symbol.info)
}
Expand Down
8 changes: 8 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,14 @@ object Types {
final def containsWildcardTypes(using Context) =
existsPart(_.isInstanceOf[WildcardType], StopAt.Static, forceLazy = false)

/** Does this type contain LazyRef types? */
final def containsLazyRefs(using Context) =
val acc = new TypeAccumulator[Boolean]:
def apply(x: Boolean, tp: Type): Boolean = tp match
case _: LazyRef => true
case _ => x || foldOver(x, tp)
acc(false, this)

// ----- Higher-order combinators -----------------------------------

/** Returns true if there is a part of this type that satisfies predicate `p`.
Expand Down
19 changes: 19 additions & 0 deletions tests/pos/i15940.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
object Ops:
implicit class EitherSeqOps[E, T](private val seq: Seq[Either[E, T]]) extends AnyVal:
def sequence: Either[::[E], Seq[T]] = ???

trait BuildException
case class CompositeBuildException(ex: ::[BuildException]) extends BuildException

trait ActionableDiagnostic
trait ActionableHandler[A <: ActionableDiagnostic]:
def exec: Either[BuildException, Seq[A]]

import Ops._

val test: Either[BuildException, Seq[ActionableDiagnostic]] =
// Can be replaced with Seq[Either[BuildException, Seq[ _ <: ActionableDiagnostic]]] , but current version matches better type of missing implicit
Seq.empty[ActionableHandler[_]].map(_.exec)
.sequence
.left.map(_.head)
.map(_.flatten) // error