Skip to content

Commit e025c27

Browse files
Backport "Fix false unreachable due to opaqueness" to LTS (#20850)
Backports #19368 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 2c97278 + 495c9eb commit e025c27

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/Types.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ object Types extends TypeUtils {
195195
*/
196196
def isRef(sym: Symbol, skipRefined: Boolean = true)(using Context): Boolean = this match {
197197
case this1: TypeRef =>
198-
this1.info match { // see comment in Namer#typeDefSig
198+
this1.info match { // see comment in Namer#TypeDefCompleter#typeSig
199199
case TypeAlias(tp) => tp.isRef(sym, skipRefined)
200200
case _ => this1.symbol eq sym
201201
}

Diff for: compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

+8-10
Original file line numberDiff line numberDiff line change
@@ -659,17 +659,15 @@ object SpaceEngine {
659659
}
660660

661661
extension (tp: Type)
662-
/** A type is decomposable to children if it has a simple kind, it's sealed,
663-
* abstract (or a trait) - so its not a sealed concrete class that can be instantiated on its own,
664-
* has no anonymous children, which we wouldn't be able to name as counter-examples,
665-
* but does have children.
666-
*
667-
* A sealed trait with no subclasses is considered not decomposable and thus is treated as an opaque type.
668-
* A sealed trait with subclasses that then get removed after `refineUsingParent`, decomposes to the empty list.
669-
* So that's why we consider whether a type has children. */
670662
def isDecomposableToChildren(using Context): Boolean =
671-
val cls = tp.classSymbol
672-
tp.hasSimpleKind && cls.is(Sealed) && cls.isOneOf(AbstractOrTrait) && !cls.hasAnonymousChild && cls.children.nonEmpty
663+
val sym = tp.typeSymbol // e.g. Foo[List[Int]] = type Foo (i19275)
664+
val cls = tp.classSymbol // e.g. Foo[List[Int]] = class List
665+
tp.hasSimpleKind // can't decompose higher-kinded types
666+
&& cls.is(Sealed)
667+
&& cls.isOneOf(AbstractOrTrait) // ignore sealed non-abstract classes
668+
&& !cls.hasAnonymousChild // can't name anonymous classes as counter-examples
669+
&& cls.children.nonEmpty // can't decompose without children
670+
&& !sym.isOpaqueAlias // can't instantiate subclasses to conform to an opaque type (i19275)
673671

674672
val ListOfNoType = List(NoType)
675673
val ListOfTypNoType = ListOfNoType.map(Typ(_, decomposed = true))

Diff for: tests/warn/i19275.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
opaque type Foo[A] <: A = A
2+
3+
class Test:
4+
def t1(x: Option[Foo[List[Int]]]): Unit = x match
5+
case Some(foo) =>
6+
case None =>

0 commit comments

Comments
 (0)