Skip to content

Commit 63fb4e7

Browse files
authored
Merge pull request #12000 from dotty-staging/fix-11995
Revert "Recursively check nonvariant arguments of base types for realizability"
2 parents f655eeb + 6549806 commit 63fb4e7

File tree

3 files changed

+28
-60
lines changed

3 files changed

+28
-60
lines changed

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

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ object CheckRealizable {
3232
class HasProblemBaseArg(typ: Type, argBounds: TypeBounds)(using Context)
3333
extends Realizability(i" has a base type $typ with possibly conflicting parameter bounds ${argBounds.lo} <: ... <: ${argBounds.hi}")
3434

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

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

170-
def baseTypeProblems(base: Type, argStr: String): List[Realizability] = base match {
171-
case base: AndType =>
172-
def factors(tp: Type): List[Type] = tp match
173-
case AndType(tp1, tp2) => factors(tp1) ++ factors(tp2)
174-
case _ => tp :: Nil
175-
for case AndType(base1, base2) <-
176-
factors(base).groupBy(_.classSymbol).values.map(_.reduce(_ & _)).toList
177-
// try to merge factors with common class symbols
178-
// if we cannot, it's a conflict
179-
yield HasProblemBase(base1, base2, argStr)
180-
case base: AppliedType =>
181-
base.argInfos.lazyZip(base.tycon.typeParams).flatMap { (arg, tparam) =>
182-
arg match
183-
case bounds @ TypeBounds(lo, hi) if !(lo <:< hi) =>
184-
new HasProblemBaseArg(base, bounds) :: Nil
185-
case arg if tparam.paramVarianceSign == 0 =>
186-
baseTypeProblems(arg, " argument")
187-
case _ =>
188-
Nil
170+
def baseTypeProblems(base: Type) = base match {
171+
case AndType(base1, base2) =>
172+
new HasProblemBase(base1, base2) :: Nil
173+
case base =>
174+
base.argInfos.collect {
175+
case bounds @ TypeBounds(lo, hi) if !(lo <:< hi) =>
176+
new HasProblemBaseArg(base, bounds)
189177
}
190-
case _ => Nil
191178
}
192179
val baseProblems =
193-
tp.baseClasses.map(_.baseTypeOf(tp)).flatMap(baseTypeProblems(_, ""))
180+
tp.baseClasses.map(_.baseTypeOf(tp)).flatMap(baseTypeProblems)
194181

195182
baseProblems.foldLeft(
196183
refinementProblems.foldLeft(

tests/neg/i11545.scala

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/pos/i11995.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
trait MyBase[A]{
2+
def foo: String
3+
}
4+
5+
case class BothThing[L, R]() extends MyBase[L & R]:
6+
def foo: String = "blather"
7+
8+
trait Has[A]
9+
10+
trait Console
11+
trait Clock
12+
13+
type ConsoleWithClock = Has[Console] with Has[Clock]
14+
15+
class Spec[R <: Has[_]]
16+
17+
object MySpec1 extends Spec[Has[Console] with Has[Clock]] // does not compile
18+
object MySpec2 extends Spec[ConsoleWithClock] // okay

0 commit comments

Comments
 (0)