Skip to content

Commit

Permalink
Merge pull request #12000 from dotty-staging/fix-11995
Browse files Browse the repository at this point in the history
Revert "Recursively check nonvariant arguments of base types for realizability"
  • Loading branch information
abgruszecki committed Apr 7, 2021
2 parents f655eeb + 6549806 commit 63fb4e7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 60 deletions.
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

0 comments on commit 63fb4e7

Please sign in to comment.