Skip to content

Commit

Permalink
Tweak approximation of type variables when computing default types
Browse files Browse the repository at this point in the history
Tweak approximation of type variables when computing the expected types
of default arguments.

Fixes #18795
  • Loading branch information
odersky committed Oct 30, 2023
1 parent 38559d7 commit 2aa87f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,10 @@ class Namer { typer: Typer =>
*/
def expectedDefaultArgType =
val originalTp = defaultParamType
val approxTp = wildApprox(originalTp)
val approxTp = withMode(Mode.TypevarsMissContext):
// assert TypevarsMissContext so that TyperState does not leak into approximation
// We approximate precisely because we want to unlink the type variable. Test case is i18795.scala.
wildApprox(originalTp)
approxTp.stripPoly match
case atp @ defn.ContextFunctionType(_, resType)
if !defn.isNonRefinedFunction(atp) // in this case `resType` is lying, gives us only the non-dependent upper bound
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/i18795.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package example

object Main extends App with Test {
load("")()
}

trait Test {

def load[T](
doLoad: T
)(
description: T => Option[String] = (x: T) => None // <--- compile error here
): Unit = ???

}

0 comments on commit 2aa87f2

Please sign in to comment.