diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 1c346ac7af20..d8e9c413decb 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -189,7 +189,7 @@ object Applications { getUnapplySelectors(getTp, args, pos) else if (unapplyResult.widenSingleton isRef defn.BooleanClass) Nil - else if (defn.isProductSubType(unapplyResult)) + else if (defn.isProductSubType(unapplyResult) && productArity(unapplyResult, pos) != 0) productSelectorTypes(unapplyResult, pos) // this will cause a "wrong number of arguments in pattern" error later on, // which is better than the message in `fail`. diff --git a/tests/neg/i13960.check b/tests/neg/i13960.check new file mode 100644 index 000000000000..ce280f48be4c --- /dev/null +++ b/tests/neg/i13960.check @@ -0,0 +1,6 @@ +-- [E108] Declaration Error: tests/neg/i13960.scala:13:10 -------------------------------------------------------------- +13 | case A() => // error + | ^^^ + | A is not a valid result type of an unapply method of an extractor. + +longer explanation available when compiling with `-explain` diff --git a/tests/neg/i13960.scala b/tests/neg/i13960.scala new file mode 100644 index 000000000000..54ae513598f1 --- /dev/null +++ b/tests/neg/i13960.scala @@ -0,0 +1,15 @@ +class A() extends Product { + override def canEqual(that: Any) = true + override def productArity = 0 + override def productElement(n: Int) = null +} + +object A { + def unapply(a: A): A = a +} + +object Main { + (new A) match { + case A() => // error + } +}