Skip to content
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

Tweak approximation of type variables when computing default types #18798

Merged
merged 1 commit into from
Oct 31, 2023
Merged
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
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this sentence mean to describe the regular way approximation works, as in when TypevarsMissContext is not set, or am I misunderstanding?

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 = ???

}
Loading