Skip to content

Commit 74cc1b6

Browse files
committed
Fix CI
1 parent ce4f97d commit 74cc1b6

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ object desugar {
13361336
Function(param :: Nil, Block(vdefs, body))
13371337
}
13381338

1339-
def makeContextualFunction(formals: List[TypeTree], body: Tree, isErased: Boolean)(implicit ctx: Context): Function = {
1339+
def makeContextualFunction(formals: List[Tree], body: Tree, isErased: Boolean)(implicit ctx: Context): Function = {
13401340
val mods = if (isErased) Given | Erased else Given
13411341
val params = makeImplicitParameters(formals, mods)
13421342
FunctionWithMods(params, body, Modifiers(mods))

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2469,7 +2469,34 @@ class Typer extends Namer
24692469

24702470
protected def makeContextualFunction(tree: untpd.Tree, pt: Type)(using Context): Tree = {
24712471
val defn.FunctionOf(formals, _, true, _) = pt.dropDependentRefinement
2472-
val ifun = desugar.makeContextualFunction(formals.map(_ => untpd.TypeTree()), tree, defn.isErasedFunctionType(pt))
2472+
2473+
// The getter of default parameters may reach here.
2474+
// Given the code below
2475+
//
2476+
// class Foo[A](run: A ?=> Int) {
2477+
// def foo[T](f: T ?=> Int = run) = ()
2478+
// }
2479+
//
2480+
// it desugars to
2481+
//
2482+
// class Foo[A](run: A ?=> Int) {
2483+
// def foo$default$1[T] = run
2484+
// def foo[T](f: T ?=> Int = run) = ()
2485+
// }
2486+
//
2487+
// The expected type for checking `run` in `foo$default$1` is
2488+
//
2489+
// <?> ?=> Int
2490+
//
2491+
// see tests/pos/i7778b.scala
2492+
2493+
val paramTypes = {
2494+
val hasWildcard = formals.exists(_.isInstanceOf[WildcardType])
2495+
if hasWildcard then formals.map(_ => untpd.TypeTree())
2496+
else formals.map(untpd.TypeTree)
2497+
}
2498+
2499+
val ifun = desugar.makeContextualFunction(paramTypes, tree, defn.isErasedFunctionType(pt))
24732500
typr.println(i"make contextual function $tree / $pt ---> $ifun")
24742501
typed(ifun, pt)
24752502
}

0 commit comments

Comments
 (0)