Skip to content

Commit e2efddc

Browse files
authored
Merge pull request #15341 from dotty-staging/fix-15319-v2
Partial revert of #13780
2 parents 399b4af + 02f775f commit e2efddc

File tree

9 files changed

+14
-56
lines changed

9 files changed

+14
-56
lines changed

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -756,13 +756,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
756756
}
757757

758758
def tryBaseType(cls2: Symbol) = {
759-
val allowBaseType = !caseLambda.exists || (tp1 match {
760-
case tp: TypeRef if tp.symbol.isClass => true
761-
case AppliedType(tycon: TypeRef, _) if tycon.symbol.isClass => true
762-
case _ => false
763-
})
764759
val base = nonExprBaseType(tp1, cls2)
765-
if (base.exists && base.ne(tp1) && allowBaseType)
760+
if (base.exists && (base `ne` tp1))
766761
isSubType(base, tp2, if (tp1.isRef(cls2)) approx else approx.addLow) ||
767762
base.isInstanceOf[OrType] && fourthTry
768763
// if base is a disjunction, this might have come from a tp1 type that
@@ -781,7 +776,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
781776
|| narrowGADTBounds(tp1, tp2, approx, isUpper = true))
782777
&& (tp2.isAny || GADTusage(tp1.symbol))
783778

784-
!caseLambda.exists && isSubType(hi1, tp2, approx.addLow) || compareGADT || tryLiftedToThis1
779+
isSubType(hi1, tp2, approx.addLow) || compareGADT || tryLiftedToThis1
785780
case _ =>
786781
// `Mode.RelaxedOverriding` is only enabled when checking Java overriding
787782
// in explicit nulls, and `Null` becomes a bottom type, which allows

compiler/test/dotc/pos-test-pickling.blacklist

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ i9999.scala
4343
7512.scala
4444
i6505.scala
4545
i15158.scala
46+
i15155.scala
4647

4748
# Opaque type
4849
i5720.scala

compiler/test/dotty/tools/dotc/CompilationTests.scala

-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ class CompilationTests {
200200
@Test def runAll: Unit = {
201201
implicit val testGroup: TestGroup = TestGroup("runAll")
202202
aggregateTests(
203-
compileFile("tests/run-custom-args/typeclass-derivation1.scala", defaultOptions.without(yCheckOptions: _*)),
204203
compileFile("tests/run-custom-args/tuple-cons.scala", allowDeepSubtypes),
205204
compileFile("tests/run-custom-args/i5256.scala", allowDeepSubtypes),
206205
compileFile("tests/run-custom-args/no-useless-forwarders.scala", defaultOptions and "-Xmixin-force-forwarders:false"),

tests/neg/11982.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ type Head[X] = X match {
44
}
55

66
object Unpair {
7-
def unpair[X <: Tuple2[Any, Any]]: Head[X] = 1 // error
8-
unpair[Tuple2["msg", 42]]: "msg"
7+
def unpair[X <: Tuple2[Any, Any]]: Head[X] = 1
8+
unpair[Tuple2["msg", 42]]: "msg" // error
99
}
1010

1111

@@ -14,8 +14,8 @@ type Head2[X] = X match {
1414
}
1515

1616
object Unpair2 {
17-
def unpair[X <: Tuple2[Tuple2[Any, Any], Tuple2[Any, Any]]]: Head2[X] = 1 // error
18-
unpair[Tuple2[Tuple2["msg", 42], Tuple2[41, 40]]]: "msg"
17+
def unpair[X <: Tuple2[Tuple2[Any, Any], Tuple2[Any, Any]]]: Head2[X] = 1
18+
unpair[Tuple2[Tuple2["msg", 42], Tuple2[41, 40]]]: "msg" // error
1919
}
2020

2121

@@ -35,6 +35,6 @@ type Head4[X] = X match {
3535
}
3636

3737
object Unpair4 {
38-
def unpair[X <: Foo[Any, Any]]: Head4[Foo[X, X]] = 1 // error
39-
unpair[Foo["msg", 42]]: "msg"
38+
def unpair[X <: Foo[Any, Any]]: Head4[Foo[X, X]] = 1
39+
unpair[Foo["msg", 42]]: "msg" // error
4040
}

tests/neg/6570-1.scala

+1-15
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,7 @@ class Asploder extends Root[Cov[Box[Int & String]]] {
3333
}
3434

3535
object Main {
36-
def foo[T <: Cov[Box[Int]]](c: Root[T]): Trait2 = c.thing // error
37-
// ^^^^^^^
38-
// Found: M[T]
39-
// Required: Trait2
40-
//
41-
// where: T is a type in method foo with bounds <: Cov[Box[Int]]
42-
//
43-
//
44-
// Note: a match type could not be fully reduced:
45-
//
46-
// trying to reduce M[T]
47-
// failed since selector T
48-
// does not match case Cov[x] => N[x]
49-
// and cannot be shown to be disjoint from it either.
50-
36+
def foo[T <: Cov[Box[Int]]](c: Root[T]): Trait2 = c.thing
5137
def explode = foo(new Asploder)
5238

5339
def main(args: Array[String]): Unit =

tests/neg/6570.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object UpperBoundParametricVariant {
2121
trait Child[A <: Cov[Int]] extends Root[A]
2222

2323
// we reduce `M[T]` to `Trait2`, even though we cannot be certain of that
24-
def foo[T <: Cov[Int]](c: Child[T]): Trait2 = c.thing // error
24+
def foo[T <: Cov[Int]](c: Child[T]): Trait2 = c.thing
2525

2626
class Asploder extends Child[Cov[String & Int]] {
2727
def thing = new Trait1 {} // error
@@ -42,7 +42,7 @@ object InheritanceVariant {
4242

4343
trait Child extends Root { type B <: { type A <: Int } }
4444

45-
def foo(c: Child): Trait2 = c.thing // error
45+
def foo(c: Child): Trait2 = c.thing
4646

4747
class Asploder extends Child {
4848
type B = { type A = String & Int }
@@ -98,7 +98,7 @@ object UpperBoundVariant {
9898

9999
trait Child extends Root { type A <: Cov[Int] }
100100

101-
def foo(c: Child): Trait2 = c.thing // error
101+
def foo(c: Child): Trait2 = c.thing
102102

103103
class Asploder extends Child {
104104
type A = Cov[String & Int]

tests/neg/i15155.check

-11
This file was deleted.

tests/neg/i15155.scala renamed to tests/pos/i15155.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ type EnumValue[A <: Enumeration] = A match {
77

88
// https://github.com/json4s/json4s/blob/355d8751391773e0d79d04402a4f9fb7bfc684ec/ext/src/main/scala/org/json4s/ext/EnumSerializer.scala#L25-L26
99
class EnumSerializer[E <: Enumeration: ClassTag](enumeration: E) {
10-
val EnumerationClass = classOf[EnumValue[E]] // error
10+
val EnumerationClass = classOf[EnumValue[E]]
1111
}

tests/run-custom-args/typeclass-derivation1.scala renamed to tests/run/typeclass-derivation1.scala

-12
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,3 @@ object Test extends App {
9696
assert(!eq2.equals(yss, xss))
9797
assert(eq2.equals(yss, yss))
9898
}
99-
100-
// -Ycheck failure minimized to:
101-
// import scala.compiletime.*
102-
// object Eq {
103-
// inline def deriveForProduct[Elems <: Tuple](xs: Elems): Boolean = inline erasedValue[Elems] match {
104-
// case _: (elem *: elems1) =>
105-
// val xs1 = xs.asInstanceOf[elem *: elems1]
106-
// deriveForProduct(xs1.tail)
107-
// case _: EmptyTuple =>
108-
// true
109-
// }
110-
// }

0 commit comments

Comments
 (0)