From 7eb4042d5b1462ce14e1ee542cdf564b06965d69 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 12 Mar 2020 16:51:34 +0100 Subject: [PATCH 1/2] Fix #8516: Keep correct parameter names when selecting in refined types --- compiler/src/dotty/tools/dotc/core/Types.scala | 8 +++++++- tests/pos/i8516.scala | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i8516.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 4f627c815073..d51210af0b73 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -673,10 +673,16 @@ 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 => + 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 From 465b81b2586e64c02d07841ca813122b7fbba1f2 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 12 Mar 2020 20:51:21 +0100 Subject: [PATCH 2/2] Add explanation comment --- compiler/src/dotty/tools/dotc/core/Types.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index d51210af0b73..55f6c6e06662 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -680,6 +680,7 @@ object Types { 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