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

Backport: Revert "Recursively check nonvariant arguments of base types for realizability" #12067

Merged
merged 2 commits into from
Apr 14, 2021
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
33 changes: 10 additions & 23 deletions compiler/src/dotty/tools/dotc/core/CheckRealizable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ object CheckRealizable {
class HasProblemBaseArg(typ: Type, argBounds: TypeBounds)(using Context)
extends Realizability(i" has a base type $typ with possibly conflicting parameter bounds ${argBounds.lo} <: ... <: ${argBounds.hi}")

class HasProblemBase(base1: Type, base2: Type, argStr: String)(using Context)
extends Realizability(i" has conflicting base type${argStr}s $base1 and $base2")
class HasProblemBase(base1: Type, base2: Type)(using Context)
extends Realizability(i" has conflicting base types $base1 and $base2")

class HasProblemField(fld: SingleDenotation, problem: Realizability)(using Context)
extends Realizability(i" has a member $fld which is not a legal path\nsince ${fld.symbol.name}: ${fld.info}${problem.msg}")
Expand Down Expand Up @@ -167,30 +167,17 @@ class CheckRealizable(using Context) {
new HasProblemBounds(name, mbr.info)
}

def baseTypeProblems(base: Type, argStr: String): List[Realizability] = base match {
case base: AndType =>
def factors(tp: Type): List[Type] = tp match
case AndType(tp1, tp2) => factors(tp1) ++ factors(tp2)
case _ => tp :: Nil
for case AndType(base1, base2) <-
factors(base).groupBy(_.classSymbol).values.map(_.reduce(_ & _)).toList
// try to merge factors with common class symbols
// if we cannot, it's a conflict
yield HasProblemBase(base1, base2, argStr)
case base: AppliedType =>
base.argInfos.lazyZip(base.tycon.typeParams).flatMap { (arg, tparam) =>
arg match
case bounds @ TypeBounds(lo, hi) if !(lo <:< hi) =>
new HasProblemBaseArg(base, bounds) :: Nil
case arg if tparam.paramVarianceSign == 0 =>
baseTypeProblems(arg, " argument")
case _ =>
Nil
def baseTypeProblems(base: Type) = base match {
case AndType(base1, base2) =>
new HasProblemBase(base1, base2) :: Nil
case base =>
base.argInfos.collect {
case bounds @ TypeBounds(lo, hi) if !(lo <:< hi) =>
new HasProblemBaseArg(base, bounds)
}
case _ => Nil
}
val baseProblems =
tp.baseClasses.map(_.baseTypeOf(tp)).flatMap(baseTypeProblems(_, ""))
tp.baseClasses.map(_.baseTypeOf(tp)).flatMap(baseTypeProblems)

baseProblems.foldLeft(
refinementProblems.foldLeft(
Expand Down
37 changes: 0 additions & 37 deletions tests/neg/i11545.scala

This file was deleted.

18 changes: 18 additions & 0 deletions tests/pos/i11995.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
trait MyBase[A]{
def foo: String
}

case class BothThing[L, R]() extends MyBase[L & R]:
def foo: String = "blather"

trait Has[A]

trait Console
trait Clock

type ConsoleWithClock = Has[Console] with Has[Clock]

class Spec[R <: Has[_]]

object MySpec1 extends Spec[Has[Console] with Has[Clock]] // does not compile
object MySpec2 extends Spec[ConsoleWithClock] // okay