Skip to content

Avoid auto-tupling in unapply unless a tuple is expected #13063

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

Merged
merged 1 commit into from
Jul 14, 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 @@ -1360,7 +1360,7 @@ trait Applications extends Compatibility {
for (argType <- argTypes) assert(!isBounds(argType), unapplyApp.tpe.show)
val bunchedArgs = argTypes match {
case argType :: Nil =>
if (args.lengthCompare(1) > 0 && Feature.autoTuplingEnabled) untpd.Tuple(args) :: Nil
if (args.lengthCompare(1) > 0 && Feature.autoTuplingEnabled && defn.isTupleType(argType)) untpd.Tuple(args) :: Nil
else args
case _ => args
}
Expand Down
6 changes: 6 additions & 0 deletions tests/neg/i10757.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- [E107] Syntax Error: tests/neg/i10757.scala:4:10 --------------------------------------------------------------------
4 | case Var(name, _) => name: String // error
| ^^^^^^^^^^^^
| Wrong number of argument patterns for Var; expected: (String)

longer explanation available when compiling with `-explain`
4 changes: 4 additions & 0 deletions tests/neg/i10757.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
case class Var(name: String)

@main def f = Var("a") match
case Var(name, _) => name: String // error