Skip to content

Improve inference of dependent function types to fix #5526 #5528

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

Closed
Closed
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
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
21 changes: 21 additions & 0 deletions tests/pos/i5526.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}