Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail compilation of attempting a 0-arity product extraction #14029

Merged
merged 1 commit into from
Dec 8, 2021
Merged
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
6 changes: 6 additions & 0 deletions tests/neg/i13960.check
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think our checkfiles have ansi color escape codes normally

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't investigate why we're getting it here, in part because it auto-generated and passes...


longer explanation available when compiling with `-explain`
15 changes: 15 additions & 0 deletions tests/neg/i13960.scala
Original file line number Diff line number Diff line change
@@ -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
}
}