Skip to content

Commit

Permalink
Avoid auto-tupling in unapply unless a tuple is expected
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Jul 13, 2021
1 parent 54b89b1 commit fb6769e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
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
7 changes: 7 additions & 0 deletions tests/neg/i10757.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- [E007] Type Mismatch Error: tests/neg/i10757.scala:4:23 -------------------------------------------------------------
4 | case Var(name, _) => name: String // error
| ^^^^
| Found: (name : Any)
| Required: 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

0 comments on commit fb6769e

Please sign in to comment.