diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index e1f5e59e3259..f6b46fb59862 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1155,7 +1155,12 @@ class Namer { typer: Typer => case TypeTree() => checkMembersOK(inferredType, mdef.pos) case DependentTypeTree(tpFun) => - tpFun(paramss.head) + val tpe = tpFun(paramss.head) + if (!isFullyDefined(tpe, ForceDegree.none)) { + typedAheadExpr(mdef.rhs, tpe).tpe + } else { + tpe + } case TypedSplice(tpt: TypeTree) if !isFullyDefined(tpt.tpe, ForceDegree.none) => val rhsType = typedAheadExpr(mdef.rhs, tpt.tpe).tpe mdef match { diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index e11447c2a461..1b60fb13f710 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1215,7 +1215,7 @@ class Typer extends Namer } case _ => tree.withType( - if (isFullyDefined(pt, ForceDegree.none)) pt else UnspecifiedErrorType) + if (isFullyDefined(pt, ForceDegree.noBottom)) pt else UnspecifiedErrorType) } } diff --git a/tests/pos/i5526.scala b/tests/pos/i5526.scala new file mode 100644 index 000000000000..689d02c77f29 --- /dev/null +++ b/tests/pos/i5526.scala @@ -0,0 +1,21 @@ +trait A +object test1 { + def foo[E](f: (a: A) => (a.type, E)): E = { + val a = new A {} + f(a)._2 + } + + val res = foo { a => (a, 42) } + val x: Int = res +} + +object test2 { + trait F[A, -E] + def empty[A](value: A): F[A, Any] = ??? + + def hof[R](f: (p: AnyRef) => F[R, p.type]): F[R, Any] = ??? + + hof { p => + empty(42) + } +} \ No newline at end of file