Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,8 @@ object SpaceEngine {
else NoType
}.filter(_.exists)
parts
case tref: TypeRef if tref.symbol.isOpaqueAlias && !tref.info.hiBound.isNothingType =>
rec(tref.info.hiBound, mixins)
case _ => ListOfNoType
end rec

Expand Down Expand Up @@ -853,7 +855,11 @@ object SpaceEngine {
}) ||
tpw.isRef(defn.BooleanClass) ||
classSym.isAllOf(JavaEnum) ||
classSym.is(Case)
classSym.is(Case) ||
(tpw.isInstanceOf[TypeRef] && {
val tref = tpw.asInstanceOf[TypeRef]
tref.symbol.isOpaqueAlias && !tref.info.hiBound.isNothingType
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I extract this logic into a separate function? If so, where would be a good place to put it?

})

!sel.tpe.hasAnnotation(defn.UncheckedAnnot)
&& !sel.tpe.hasAnnotation(defn.RuntimeCheckedAnnot)
Expand Down
18 changes: 18 additions & 0 deletions tests/pos/i23620.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
trait Foo
trait Bar

type FooOrBar = FooOrBar.Type
object FooOrBar:
opaque type Type <: (Foo | Bar) = Foo | Bar

def bar: FooOrBar = new Bar {}

trait Buz

@main def main =
val p: FooOrBar | Buz = FooOrBar.bar

p match
case _: Foo => println("foo")
case _: Buz => println("buz")
case _: Bar => println("bar")
16 changes: 16 additions & 0 deletions tests/warn/i23620b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- [E029] Pattern Match Exhaustivity Warning: tests/warn/i23620b.scala:20:2 --------------------------------------------
20 | p match // warn
| ^
| match may not be exhaustive.
|
| It would fail on pattern case: _: Bar
|
| longer explanation available when compiling with `-explain`
-- [E029] Pattern Match Exhaustivity Warning: tests/warn/i23620b.scala:23:2 --------------------------------------------
23 | p2 match { //warn
| ^^
| match may not be exhaustive.
|
| It would fail on pattern case: _: Bar
|
| longer explanation available when compiling with `-explain`
25 changes: 25 additions & 0 deletions tests/warn/i23620b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
trait Foo
trait Bar

type FooOrBar = FooOrBar.Type
object FooOrBar:
opaque type Type <: (Foo | Bar) = Foo | Bar

def bar: FooOrBar = new Bar {}

type OnlyFoo = OnlyFoo.Type
object OnlyFoo:
opaque type Type <: (Foo | Bar) = Foo

def foo: OnlyFoo = new Foo {}

@main def main =
val p: FooOrBar= FooOrBar.bar
val p2: OnlyFoo = OnlyFoo.foo

p match // warn
case _: Foo => println("foo")

p2 match { //warn
case _: Foo => println("foo")
}
Loading