Skip to content

Commit 62c0c8d

Browse files
committed
Fix #10016: Bypass normalize for context function closure arguments
Do not widen to their result type if expected type is again a context function
1 parent 6b9796c commit 62c0c8d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,9 @@ trait Applications extends Compatibility {
677677
*/
678678
class ApplicableToTrees(methRef: TermRef, args: List[Tree], resultType: Type)(using Context)
679679
extends TestApplication(methRef, methRef.widen, args, resultType) {
680-
def argType(arg: Tree, formal: Type): Type = normalize(arg.tpe, formal)
680+
def argType(arg: Tree, formal: Type): Type =
681+
if untpd.isContextualClosure(arg) && defn.isContextFunctionType(formal) then arg.tpe
682+
else normalize(arg.tpe, formal)
681683
def treeToArg(arg: Tree): Tree = arg
682684
def isVarArg(arg: Tree): Boolean = tpd.isWildcardStarArg(arg)
683685
def typeOfArg(arg: Tree): Type = arg.tpe

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,8 @@ object ProtoTypes {
630630
normalize(et.resultType, pt)
631631
case wtp =>
632632
val iftp = defn.asContextFunctionType(wtp)
633-
if (iftp.exists) normalize(iftp.dropDependentRefinement.argInfos.last, pt) else tp
633+
if iftp.exists then normalize(iftp.dropDependentRefinement.argInfos.last, pt)
634+
else tp
634635
}
635636
}
636637

tests/run/i10016.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def f(init: Int ?=> Int) : Int = 1
2+
def f(s: String)(init: Int ?=> Int) : Int = 2
3+
4+
@main def Test() =
5+
assert(f((using x:Int) => x) == 1)

0 commit comments

Comments
 (0)