Skip to content

By name match selector #4999

@allanrenucci

Description

@allanrenucci
trait Foo
final class Bar extends Foo

class Test {
  def test(xs: => Foo) = xs match {
    case xs: Bar => 1
    case _       => 2
  }
}
-- Error: tests/allan/Test.scala:104:9 -----------------------------------------
104 |    case xs: Bar => 1
    |         ^
    |this case is unreachable since trait Function0 and class Bar are unrelated

However, this is not an issue with the exhaustivity checker. It fails Ycheck:

checking tests/allan/Test.scala after phase MegaPhase{pruneErasedDefs, vcInlineMethods, seqLiterals, intercepted, getters, elimByName, collectNullableFields, elimOuterSelect, augmentScala2Traits, resolveSuper, primitiveForwarders, functionXXLForwarders, arrayConstructors}
exception while typing case val x1: (() => Foo)(xs) = xs.apply() of class class dotty.tools.dotc.ast.Trees$ValDef # 777
exception while typing {
  case val x1: (() => Foo)(xs) = xs.apply()
  if x1.$isInstanceOf$[Bar] then 
    {
      case val x2: Bar = x1.asInstanceOf[Bar]
      case val xs: Bar = x2
      1
    }
   else 2
} of class class dotty.tools.dotc.ast.Trees$Block # 778
...
Exception in thread "main" java.lang.AssertionError: assertion failed: found:    Foo
required: (() => Foo)(xs)

The type we get for case val x1 after ElimByName ((() => Foo)(xs)) is clearly wrong. Should be Foo

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions