Skip to content

Commit 0dfe593

Browse files
authored
Allow inferred parameter types always, when eta-expanding (#18771)
2 parents 85908de + a196167 commit 0dfe593

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4178,11 +4178,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
41784178
val funExpected = functionExpected
41794179
val arity =
41804180
if funExpected then
4181-
if !isFullyDefined(pt, ForceDegree.none) && isFullyDefined(wtp, ForceDegree.none) then
4182-
// if method type is fully defined, but expected type is not,
4183-
// prioritize method parameter types as parameter types of the eta-expanded closure
4184-
0
4185-
else defn.functionArity(ptNorm)
4181+
defn.functionArity(ptNorm)
41864182
else
41874183
val nparams = wtp.paramInfos.length
41884184
if nparams > 1

tests/neg/i5976.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
object Test {
22
def f(i: => Int) = i + i
3-
val res = List(42).map(f) // error
3+
val res = List(42).map(f)
44

55
val g: (=> Int) => Int = f
66
val h: Int => Int = g // error
7-
}
7+
}

tests/pos/i18453.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait Box[T]
2+
3+
class Test:
4+
def f[A, B](c: A => A & B)(using ba: Box[A]): Unit = ???
5+
6+
def g[X, Y](using bx: Box[X]): Unit =
7+
def d(t: X): X & Y = t.asInstanceOf[X & Y]
8+
f(d)

tests/pos/i18453.workaround.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait Box[T]
2+
3+
class Test:
4+
def f[A, B](c: A => A & B)(using ba: Box[A]): Unit = ???
5+
6+
def g[X, Y](using bx: Box[X]): Unit =
7+
def d(t: X): X & Y = t.asInstanceOf[X & Y]
8+
f(u => d(u))

tests/semanticdb/metac.expect

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ Language => Scala
10821082
Symbols => 181 entries
10831083
Occurrences => 159 entries
10841084
Diagnostics => 1 entries
1085-
Synthetics => 6 entries
1085+
Synthetics => 5 entries
10861086

10871087
Symbols:
10881088
_empty_/Enums. => final object Enums extends Object { self: Enums.type => +30 decls }
@@ -1265,7 +1265,7 @@ _empty_/Enums.unwrap().(ev) => implicit given param ev: <:<[A, Option[B]]
12651265
_empty_/Enums.unwrap().(opt) => param opt: Option[A]
12661266
_empty_/Enums.unwrap().[A] => typeparam A
12671267
_empty_/Enums.unwrap().[B] => typeparam B
1268-
local0 => param x: Option[B]
1268+
local0 => param x: A
12691269

12701270
Occurrences:
12711271
[0:7..0:12): Enums <- _empty_/Enums.
@@ -1433,7 +1433,6 @@ Diagnostics:
14331433

14341434
Synthetics:
14351435
[52:9..52:13):Refl => *.unapply[Option[B]]
1436-
[52:31..52:50):identity[Option[B]] => *[Function1[A, Option[B]]]
14371436
[54:14..54:18):Some => *.apply[Some[Int]]
14381437
[54:14..54:34):Some(Some(1)).unwrap => *(given_<:<_T_T[Option[Int]])
14391438
[54:19..54:23):Some => *.apply[Int]

0 commit comments

Comments
 (0)