Skip to content

Commit d750b47

Browse files
authored
Merge pull request #582 from tgodzik/revert
Revert "Merge pull request #275 from scala/backport-lts-3.3-22604"
2 parents ed80ad8 + ab201d4 commit d750b47

File tree

10 files changed

+35
-59
lines changed

10 files changed

+35
-59
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ object SpaceEngine {
801801
}
802802

803803
private def exhaustivityCheckable(sel: Tree)(using Context): Boolean = {
804+
val seen = collection.mutable.Set.empty[Symbol]
804805

805806
// Possible to check everything, but be compatible with scalac by default
806807
def isCheckable(tp: Type): Boolean =
@@ -815,7 +816,10 @@ object SpaceEngine {
815816
}) ||
816817
tpw.isRef(defn.BooleanClass) ||
817818
classSym.isAllOf(JavaEnumTrait) ||
818-
classSym.is(Case)
819+
classSym.is(Case) && {
820+
if seen.add(classSym) then productSelectorTypes(tpw, sel.srcPos).exists(isCheckable(_))
821+
else true // recursive case class: return true and other members can still fail the check
822+
}
819823

820824
!sel.tpe.hasAnnotation(defn.UncheckedAnnot)
821825
&& {

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,30 +1298,29 @@ trait Implicits:
12981298
if alt1.isExtension then
12991299
// Fall back: if both results are extension method applications,
13001300
// compare the extension methods instead of their wrappers.
1301-
def stripExtension(alt: SearchSuccess) =
1302-
methPart(stripApply(alt.tree)).tpe: @unchecked match { case ref: TermRef => ref }
1303-
val ref1 = stripExtension(alt1)
1304-
val ref2 = stripExtension(alt2)
1305-
// ref1 and ref2 might refer to type variables owned by
1306-
// alt1.tstate and alt2.tstate respectively, to compare the
1307-
// alternatives correctly we need a TyperState that includes
1308-
// constraints from both sides, see
1309-
// tests/*/extension-specificity2.scala for test cases.
1310-
val constraintsIn1 = alt1.tstate.constraint ne ctx.typerState.constraint
1311-
val constraintsIn2 = alt2.tstate.constraint ne ctx.typerState.constraint
1312-
def exploreState(alt: SearchSuccess): TyperState =
1313-
alt.tstate.fresh(committable = false)
1314-
val comparisonState =
1315-
if constraintsIn1 && constraintsIn2 then
1316-
exploreState(alt1).mergeConstraintWith(alt2.tstate)
1317-
else if constraintsIn1 then
1318-
exploreState(alt1)
1319-
else if constraintsIn2 then
1320-
exploreState(alt2)
1321-
else
1322-
ctx.typerState
1323-
1324-
diff = inContext(ctx.withTyperState(comparisonState)):
1301+
def stripExtension(alt: SearchSuccess) = methPart(stripApply(alt.tree)).tpe
1302+
((stripExtension(alt1), stripExtension(alt2)) : @unchecked) match
1303+
case (ref1: TermRef, ref2: TermRef) =>
1304+
// ref1 and ref2 might refer to type variables owned by
1305+
// alt1.tstate and alt2.tstate respectively, to compare the
1306+
// alternatives correctly we need a TyperState that includes
1307+
// constraints from both sides, see
1308+
// tests/*/extension-specificity2.scala for test cases.
1309+
val constraintsIn1 = alt1.tstate.constraint ne ctx.typerState.constraint
1310+
val constraintsIn2 = alt2.tstate.constraint ne ctx.typerState.constraint
1311+
def exploreState(alt: SearchSuccess): TyperState =
1312+
alt.tstate.fresh(committable = false)
1313+
val comparisonState =
1314+
if constraintsIn1 && constraintsIn2 then
1315+
exploreState(alt1).mergeConstraintWith(alt2.tstate)
1316+
else if constraintsIn1 then
1317+
exploreState(alt1)
1318+
else if constraintsIn2 then
1319+
exploreState(alt2)
1320+
else
1321+
ctx.typerState
1322+
1323+
diff = inContext(ctx.withTyperState(comparisonState)):
13251324
compare(ref1, ref2)
13261325
else // alt1 is a conversion, prefer extension alt2 over it
13271326
diff = -1

scaladoc/src/dotty/tools/scaladoc/site/templates.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ case class TemplateFile(
102102
ctx.layouts.getOrElse(name, throw new RuntimeException(s"No layouts named $name in ${ctx.layouts}"))
103103
)
104104

105-
def asJavaElement(o: Any): Any = o match
106-
case m: Map[?, ?] => m.transform { (k, v) => asJavaElement(v) }.asJava
107-
case l: List[?] => l.map(asJavaElement).asJava
105+
def asJavaElement(o: Object): Object = o match
106+
case m: Map[_, _] => m.transform {
107+
case (k: String, v: Object) => asJavaElement(v)
108+
}.asJava
109+
case l: List[_] => l.map(x => asJavaElement(x.asInstanceOf[Object])).asJava
108110
case other => other
109111

110112
// Library requires mutable maps..

tests/pos/switches.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Test {
4242
case IntAnyVal(100) => 2
4343
case IntAnyVal(1000) => 3
4444
case IntAnyVal(10000) => 4
45-
case _ => -1
4645
}
4746
}
4847

tests/warn/t10373.scala renamed to tests/pos/t10373.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using options -deprecation -feature
1+
//> using options -Xfatal-warnings -deprecation -feature
22

33
abstract class Foo {
44
def bar(): Unit = this match {
@@ -7,7 +7,7 @@ abstract class Foo {
77
// Works fine
88
}
99

10-
def baz(that: Foo): Unit = (this, that) match { // warn: match may not be exhaustive.
10+
def baz(that: Foo): Unit = (this, that) match {
1111
case (Foo_1(), _) => //do something
1212
case (Foo_2(), _) => //do something
1313
// match may not be exhaustive

tests/warn/i15662.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ case class Composite[T](v: T)
55
def m(composite: Composite[?]): Unit =
66
composite match {
77
case Composite[Int](v) => println(v) // warn: cannot be checked at runtime
8-
case _ => println("OTHER")
98
}
109

1110
def m2(composite: Composite[?]): Unit =

tests/warn/i21218.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ def Test[U, A](thisElem: A, thatElem: U) = {
66
case (`passedEnd`, r: U @unchecked) => (thisElem, r)
77
case (l: A @unchecked, `passedEnd`) => (l, thatElem)
88
case t: (A, U) @unchecked => t // false-positive warning
9-
case (t1, t2) => (t1, t2)
109
}
1110
}

tests/warn/i22590.arity2.scala

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

tests/warn/i22590.scala

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

tests/warn/opaque-match.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ def Test[T] =
1313
case _: C => ??? // ok
1414
C() match
1515
case _: O.T => ??? // warn
16-
case _ => ???
1716
C() match
1817
case _: T => ??? // warn
19-
case _ => ???
2018

2119
(??? : Any) match
2220
case _: List[O.T] => ??? // warn

0 commit comments

Comments
 (0)