Skip to content

Commit 2aa87f2

Browse files
committed
Tweak approximation of type variables when computing default types
Tweak approximation of type variables when computing the expected types of default arguments. Fixes #18795
1 parent 38559d7 commit 2aa87f2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,10 @@ class Namer { typer: Typer =>
18961896
*/
18971897
def expectedDefaultArgType =
18981898
val originalTp = defaultParamType
1899-
val approxTp = wildApprox(originalTp)
1899+
val approxTp = withMode(Mode.TypevarsMissContext):
1900+
// assert TypevarsMissContext so that TyperState does not leak into approximation
1901+
// We approximate precisely because we want to unlink the type variable. Test case is i18795.scala.
1902+
wildApprox(originalTp)
19001903
approxTp.stripPoly match
19011904
case atp @ defn.ContextFunctionType(_, resType)
19021905
if !defn.isNonRefinedFunction(atp) // in this case `resType` is lying, gives us only the non-dependent upper bound

tests/pos/i18795.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package example
2+
3+
object Main extends App with Test {
4+
load("")()
5+
}
6+
7+
trait Test {
8+
9+
def load[T](
10+
doLoad: T
11+
)(
12+
description: T => Option[String] = (x: T) => None // <--- compile error here
13+
): Unit = ???
14+
15+
}

0 commit comments

Comments
 (0)