Skip to content

Commit

Permalink
Allow autotupling if fn's param is a type param
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Oct 9, 2024
1 parent 3408ed7 commit d93cc60
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,10 @@ trait Applications extends Compatibility {

def isCorrectUnaryFunction(alt: TermRef): Boolean =
val formals = params(alt)
formals.length == 1 && ptIsCorrectProduct(formals.head, args)
formals.lengthIs == 1 && {
ptIsCorrectProduct(formals.head, args)
| formals.head.dealias.isInstanceOf[TypeParamRef] // eg. i21682
}

val numArgs = args.length
if numArgs > 1
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/i21682.1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
sealed abstract class Gen[+T1]
given [T2]: Conversion[T2, Gen[T2]] = ???

trait Show[T3]
given Show[Boolean] = ???
given [A1: Show, B1: Show, C1: Show]: Show[(A1, B1, C1)] = ???

object ForAll:
def apply[A2: Show, B2](f: A2 => B2): Unit = ???
def apply[A3: Show, B3: Show, C3](f: (A3, B3) => C3): Unit = ???
def apply[A4: Show, B4](gen: Gen[A4])(f: A4 => B4): Unit = ???

@main def Test =
ForAll: (b1: Boolean, b2: Boolean, b3: Boolean) =>
???
7 changes: 7 additions & 0 deletions tests/pos/i21682.2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object ForAll:
def apply[A1, B](f: A1 => B): Unit = ???
def apply[A1, A2, B](f: (A1, A2) => B): Unit = ???

@main def Test =
ForAll: (b1: Boolean, b2: Boolean, b3: Boolean) =>
???

0 comments on commit d93cc60

Please sign in to comment.