diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 647ac76d5243..947bdc0c8ecc 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -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 diff --git a/tests/pos/i18795.scala b/tests/pos/i18795.scala new file mode 100644 index 000000000000..56b068e9421f --- /dev/null +++ b/tests/pos/i18795.scala @@ -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 = ??? + +} \ No newline at end of file