File tree 3 files changed +22
-1
lines changed
compiler/src/dotty/tools/dotc/typer
3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ object Applications {
189
189
getUnapplySelectors(getTp, args, pos)
190
190
else if (unapplyResult.widenSingleton isRef defn.BooleanClass )
191
191
Nil
192
- else if (defn.isProductSubType(unapplyResult))
192
+ else if (defn.isProductSubType(unapplyResult) && productArity(unapplyResult, pos) != 0 )
193
193
productSelectorTypes(unapplyResult, pos)
194
194
// this will cause a "wrong number of arguments in pattern" error later on,
195
195
// which is better than the message in `fail`.
Original file line number Diff line number Diff line change
1
+ -- [E108] Declaration Error: tests/neg/i13960.scala:13:10 --------------------------------------------------------------
2
+ 13 | case A() => // error
3
+ | ^^^
4
+ | [31mA[0m is not a valid result type of an unapply method of an [35mextractor[0m.
5
+
6
+ longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change
1
+ class A () extends Product {
2
+ override def canEqual (that : Any ) = true
3
+ override def productArity = 0
4
+ override def productElement (n : Int ) = null
5
+ }
6
+
7
+ object A {
8
+ def unapply (a : A ): A = a
9
+ }
10
+
11
+ object Main {
12
+ (new A ) match {
13
+ case A () => // error
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments