From 8ddfbd6013d2333753501f8e08b430becd1b4f3c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 1 Jul 2019 15:26:03 +0200 Subject: [PATCH 1/3] Fix #6734: Suppress interpolattion for extension methods Suppress interpolation in the middle of an ExtMethodApply. The reason is that the ExtMethodApply has a WildcardType, which hides information about bound type variables in the result type. --- compiler/src/dotty/tools/dotc/typer/Inferencing.scala | 4 +++- tests/pos/i6734.scala | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i6734.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index 21112947297b..59bf74cdfc9f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -384,7 +384,9 @@ trait Inferencing { this: Typer => // `qualifying`. val ownedVars = state.ownedVars - if ((ownedVars ne locked) && !ownedVars.isEmpty) { + if ((ownedVars ne locked) && !ownedVars.isEmpty && + !tree.isInstanceOf[Applications.IntegratedTypeArgs] // suppress interpolation in the middle of an extension method application + ) { val qualifying = ownedVars -- locked if (!qualifying.isEmpty) { typr.println(i"interpolate $tree: ${tree.tpe.widen} in $state, owned vars = ${state.ownedVars.toList}%, %, previous = ${locked.toList}%, % / ${state.constraint}") diff --git a/tests/pos/i6734.scala b/tests/pos/i6734.scala new file mode 100644 index 000000000000..c796a867bb92 --- /dev/null +++ b/tests/pos/i6734.scala @@ -0,0 +1,11 @@ +object Bug { + + def (ab: (A, B)) pipe2[A, B, Z](f: (A, B) => Z): Z = f(ab._1, ab._2) + + def (a: A) leftErr[A, B](b: B): A = (a, b).pipe2((a, b) => a) //Did not compile before. + def (a: A) leftOk1[A, B](b: B): A = Tuple2(a, b).pipe2((a, b) => a) //Compiles + def (a: A) leftOk2[A, B](b: B): A = { + val t = (a, b) + t.pipe2((a, b) => a) //Compiles + } +} From 869ccd9b3ebf20a4a4e8dd5fa003b43a1c1bab9c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 1 Jul 2019 22:20:29 +0200 Subject: [PATCH 2/3] move test to simplify --- compiler/src/dotty/tools/dotc/typer/Inferencing.scala | 4 +--- compiler/src/dotty/tools/dotc/typer/Typer.scala | 6 +++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index 59bf74cdfc9f..21112947297b 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -384,9 +384,7 @@ trait Inferencing { this: Typer => // `qualifying`. val ownedVars = state.ownedVars - if ((ownedVars ne locked) && !ownedVars.isEmpty && - !tree.isInstanceOf[Applications.IntegratedTypeArgs] // suppress interpolation in the middle of an extension method application - ) { + if ((ownedVars ne locked) && !ownedVars.isEmpty) { val qualifying = ownedVars -- locked if (!qualifying.isEmpty) { typr.println(i"interpolate $tree: ${tree.tpe.widen} in $state, owned vars = ${state.ownedVars.toList}%, %, previous = ${locked.toList}%, % / ${state.constraint}") diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 57aab549cfd5..2e208f210cb6 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2206,7 +2206,11 @@ class Typer extends Namer /** Interpolate and simplify the type of the given tree. */ protected def simplify(tree: Tree, pt: Type, locked: TypeVars)(implicit ctx: Context): tree.type = { - if (!tree.denot.isOverloaded) // for overloaded trees: resolve overloading before simplifying + if (!tree.denot.isOverloaded && + // for overloaded trees: resolve overloading before simplifying + !tree.isInstanceOf[Applications.IntegratedTypeArgs] + // don't interpolatie in the middle of an extension method application + ) if (!tree.tpe.widen.isInstanceOf[MethodOrPoly] // wait with simplifying until method is fully applied || tree.isDef) // ... unless tree is a definition { From 6ca6062accfd223214b484266da726efab80f215 Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 1 Jul 2019 22:57:08 +0200 Subject: [PATCH 3/3] Update compiler/src/dotty/tools/dotc/typer/Typer.scala Co-Authored-By: Guillaume Martres --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 2e208f210cb6..3c3ddbe3fff1 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2209,7 +2209,7 @@ class Typer extends Namer if (!tree.denot.isOverloaded && // for overloaded trees: resolve overloading before simplifying !tree.isInstanceOf[Applications.IntegratedTypeArgs] - // don't interpolatie in the middle of an extension method application + // don't interpolate in the middle of an extension method application ) if (!tree.tpe.widen.isInstanceOf[MethodOrPoly] // wait with simplifying until method is fully applied || tree.isDef) // ... unless tree is a definition