Skip to content

Commit 80517e5

Browse files
authored
Preserve type info when lifting stable arguments (#26063)
Fixes #25557 The type of lifted arguments was always widened, which affects the behavior of `avoid` and breaks dependent path types in the `foo(parent, isFoo)`'s result type. ```scala { val parent$1: ConcreteParent = ConcreteParent ConcreteParent.foo(parent = parent$1, isFoo = true)((_$2: ConcreteParent) => _$2.myInner) } ``` ## How much have you relied on LLM-based tools in this contribution? Extensively, for finding which code trigger the bug and how to fix it. ## How was the solution tested? Used reproducer provided from the issue.
1 parent faee244 commit 80517e5

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ abstract class Lifter {
4949

5050
/** Type assigned to a lifted temporary symbol. */
5151
protected def liftedExprType(expr: Tree)(using Context): Type =
52-
expr.tpe.widen.deskolemized
52+
val tp = expr.tpe.deskolemized
53+
if tp.isStable then tp else tp.widen
5354

5455
/** Hook for lifters that need to record or mark freshly created lifted defs. */
5556
protected def onLiftedDef(tree: Tree)(using Context): Unit = ()

tests/pos/i25557.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sealed trait Parent:
2+
sealed trait Inner[T]
3+
object ConcreteParent extends Parent:
4+
val myInner: Inner[Boolean] = ???
5+
def foo(parent: Parent, isFoo: Boolean)(f: parent.type => parent.Inner[Boolean]) = ???
6+
foo(parent = ConcreteParent, isFoo = true)(_.myInner)
7+
foo(isFoo = true, parent = ConcreteParent)(_.myInner)

0 commit comments

Comments
 (0)