From c3bce867da033c325ec728b793dd76dee43d2d81 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 23 Aug 2019 18:14:57 +0200 Subject: [PATCH 1/4] Fix #7084: Drop revealProtoOfExtMethod Don't call `revealProtoOfExtMethod` wehn constraining results in adaptation. Revealing the proottype too early disables further implicit searches, as is demonstrated by i7084.scala. The original reason to have `revealProtoOfExtMethod` was to typecheck i5773a. But it looks like this is no longer valid. i5773a now compiles regardless. --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 892ef2a15d93..4c03c679e5ee 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2485,13 +2485,6 @@ class Typer extends Namer } } - /** Reveal ignored parts of prototype when synthesizing the receiver - * of an extension method. This is necessary for pos/i5773a.scala - */ - def revealProtoOfExtMethod(tp: Type)(implicit ctx: Context): Type = - if (ctx.mode.is(Mode.SynthesizeExtMethodReceiver)) tp.deepenProto - else tp - def adaptNoArgsImplicitMethod(wtp: MethodType): Tree = { assert(wtp.isImplicitMethod) val tvarsToInstantiate = tvarsInParams(tree, locked).distinct @@ -2512,7 +2505,7 @@ class Typer extends Namer arg.tpe match { case failed: AmbiguousImplicits => val pt1 = pt.deepenProto - if ((pt1 `ne` pt) && resultMatches(wtp, pt1)) implicitArgs(formals, argIndex, pt1) + if ((pt1 `ne` pt) && constrainResult(tree.symbol, wtp, pt1)) implicitArgs(formals, argIndex, pt1) else arg :: implicitArgs(formals1, argIndex + 1, pt1) case failed: SearchFailureType if !tree.symbol.hasDefaultParams => // no need to search further, the adapt fails in any case @@ -2742,9 +2735,6 @@ class Typer extends Namer case _ => tp } - def resultMatches(wtp: Type, pt: Type) = - constrainResult(tree.symbol, wtp, revealProtoOfExtMethod(pt)) - def adaptNoArgs(wtp: Type): Tree = { val ptNorm = underlyingApplied(pt) def functionExpected = defn.isFunctionType(ptNorm) @@ -2758,7 +2748,7 @@ class Typer extends Namer case wtp: ExprType => readaptSimplified(tree.withType(wtp.resultType)) case wtp: MethodType if wtp.isImplicitMethod && - ({ resMatch = resultMatches(wtp, pt); resMatch } || !functionExpected) => + ({ resMatch = constrainResult(tree.symbol, wtp, pt); resMatch } || !functionExpected) => if (resMatch || ctx.mode.is(Mode.ImplicitsEnabled)) adaptNoArgsImplicitMethod(wtp) else { From 2ea76939964fd4c5525ea29cc8687c1d29e3d308 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 23 Aug 2019 18:21:47 +0200 Subject: [PATCH 2/4] Add test --- tests/pos/i7084.scala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/pos/i7084.scala diff --git a/tests/pos/i7084.scala b/tests/pos/i7084.scala new file mode 100644 index 000000000000..82befa148529 --- /dev/null +++ b/tests/pos/i7084.scala @@ -0,0 +1,15 @@ +object Test { + + type Foo + + given A { + def (y: Any) g given Foo: Any = ??? + } + + def f(x: Any) given Foo: Any = { + val y = x.g + y.g + + x.g.g + } +} \ No newline at end of file From bf8455461e87908c6613f5a50c6645be2fce5634 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 24 Aug 2019 12:34:24 +0200 Subject: [PATCH 3/4] Test for #7087 --- tests/pos/i7087.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/pos/i7087.scala diff --git a/tests/pos/i7087.scala b/tests/pos/i7087.scala new file mode 100644 index 000000000000..96298e31fdf0 --- /dev/null +++ b/tests/pos/i7087.scala @@ -0,0 +1,13 @@ +type Foo + +type G[A] + +type F[T] = T match { + case G[a] => String +} + +given A { + def (tup: T) g[T] given (Foo: F[T]) = ??? +} + +def f(x: G[Int]) given (Foo: String) = x.g \ No newline at end of file From 61f15bc1a879ad7e2175f083d133f74e0b80dbc3 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 24 Aug 2019 19:43:35 +0200 Subject: [PATCH 4/4] Blacklist i7087 for pickling and from-tasty tests We get in both cases a type difference where one side is an unreduced match type and the other side is its redux. --- compiler/test/dotc/pos-from-tasty.blacklist | 3 +++ compiler/test/dotc/pos-test-pickling.blacklist | 1 + 2 files changed, 4 insertions(+) diff --git a/compiler/test/dotc/pos-from-tasty.blacklist b/compiler/test/dotc/pos-from-tasty.blacklist index 1c1b2e32e86c..f3a7568dcf01 100644 --- a/compiler/test/dotc/pos-from-tasty.blacklist +++ b/compiler/test/dotc/pos-from-tasty.blacklist @@ -6,3 +6,6 @@ t3612.scala # Other failure t802.scala + +# Matchtype +i7087.scala \ No newline at end of file diff --git a/compiler/test/dotc/pos-test-pickling.blacklist b/compiler/test/dotc/pos-test-pickling.blacklist index b1068027c9f1..88bd35eb12f4 100644 --- a/compiler/test/dotc/pos-test-pickling.blacklist +++ b/compiler/test/dotc/pos-test-pickling.blacklist @@ -21,6 +21,7 @@ i939.scala typelevel0.scala matchtype.scala 6322.scala +i7087.scala # Opaque type i5720.scala