diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 4f627c815073..55f6c6e06662 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -673,10 +673,17 @@ object Types { pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, jointInfo) } else - pdenot & ( + val joint = pdenot & ( new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId), pre), pre, safeIntersection = ctx.base.pendingMemberSearches.contains(name)) + joint match + case joint: SingleDenotation + if rinfo.isInstanceOf[MethodOrPoly] && rinfo <:< joint.info => + // use `rinfo` to keep the right parameter names for named args. See i8516.scala. + joint.derivedSingleDenotation(joint.symbol, rinfo) + case _ => + joint } def goApplied(tp: AppliedType, tycon: HKTypeLambda) = diff --git a/tests/pos/i8516.scala b/tests/pos/i8516.scala new file mode 100644 index 000000000000..9e95e3e4eb02 --- /dev/null +++ b/tests/pos/i8516.scala @@ -0,0 +1,3 @@ +val x: Function1[Int, Int] { def apply(arg: Int): Int } = x => x +val x1 = x +val y = x.apply(arg = 1) \ No newline at end of file