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 { 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 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 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