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

Allow inferred parameter types always, when eta-expanding #18771

Merged
merged 1 commit into from
Nov 13, 2023
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
6 changes: 1 addition & 5 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4167,11 +4167,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
val funExpected = functionExpected
val arity =
if funExpected then
if !isFullyDefined(pt, ForceDegree.none) && isFullyDefined(wtp, ForceDegree.none) then
// if method type is fully defined, but expected type is not,
// prioritize method parameter types as parameter types of the eta-expanded closure
0
else defn.functionArity(ptNorm)
defn.functionArity(ptNorm)
else
val nparams = wtp.paramInfos.length
if nparams > 1
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/i5976.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object Test {
def f(i: => Int) = i + i
val res = List(42).map(f) // error
val res = List(42).map(f)

val g: (=> Int) => Int = f
val h: Int => Int = g // error
}
}
8 changes: 8 additions & 0 deletions tests/pos/i18453.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
trait Box[T]

class Test:
def f[A, B](c: A => A & B)(using ba: Box[A]): Unit = ???

def g[X, Y](using bx: Box[X]): Unit =
def d(t: X): X & Y = t.asInstanceOf[X & Y]
f(d)
8 changes: 8 additions & 0 deletions tests/pos/i18453.workaround.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
trait Box[T]

class Test:
def f[A, B](c: A => A & B)(using ba: Box[A]): Unit = ???

def g[X, Y](using bx: Box[X]): Unit =
def d(t: X): X & Y = t.asInstanceOf[X & Y]
f(u => d(u))
5 changes: 2 additions & 3 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ Language => Scala
Symbols => 181 entries
Occurrences => 159 entries
Diagnostics => 1 entries
Synthetics => 6 entries
Synthetics => 5 entries

Symbols:
_empty_/Enums. => final object Enums extends Object { self: Enums.type => +30 decls }
Expand Down Expand Up @@ -1253,7 +1253,7 @@ _empty_/Enums.unwrap().(ev) => implicit given param ev: <:<[A, Option[B]]
_empty_/Enums.unwrap().(opt) => param opt: Option[A]
_empty_/Enums.unwrap().[A] => typeparam A
_empty_/Enums.unwrap().[B] => typeparam B
local0 => param x: Option[B]
local0 => param x: A

Occurrences:
[0:7..0:12): Enums <- _empty_/Enums.
Expand Down Expand Up @@ -1421,7 +1421,6 @@ Diagnostics:

Synthetics:
[52:9..52:13):Refl => *.unapply[Option[B]]
[52:31..52:50):identity[Option[B]] => *[Function1[A, Option[B]]]
[54:14..54:18):Some => *.apply[Some[Int]]
[54:14..54:34):Some(Some(1)).unwrap => *(given_<:<_T_T[Option[Int]])
[54:19..54:23):Some => *.apply[Int]
Expand Down
Loading