File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -1336,7 +1336,7 @@ object desugar {
1336
1336
Function (param :: Nil , Block (vdefs, body))
1337
1337
}
1338
1338
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 = {
1340
1340
val mods = if (isErased) Given | Erased else Given
1341
1341
val params = makeImplicitParameters(formals, mods)
1342
1342
FunctionWithMods (params, body, Modifiers (mods))
Original file line number Diff line number Diff line change @@ -2469,7 +2469,34 @@ class Typer extends Namer
2469
2469
2470
2470
protected def makeContextualFunction (tree : untpd.Tree , pt : Type )(using Context ): Tree = {
2471
2471
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))
2473
2500
typr.println(i " make contextual function $tree / $pt ---> $ifun" )
2474
2501
typed(ifun, pt)
2475
2502
}
You can’t perform that action at this time.
0 commit comments