Skip to content

Fix #7084: Drop revealProtoOfExtMethod #7093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions compiler/test/dotc/pos-from-tasty.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ t3612.scala

# Other failure
t802.scala

# Matchtype
i7087.scala
1 change: 1 addition & 0 deletions compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ i939.scala
typelevel0.scala
matchtype.scala
6322.scala
i7087.scala

# Opaque type
i5720.scala
15 changes: 15 additions & 0 deletions tests/pos/i7084.scala
Original file line number Diff line number Diff line change
@@ -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
}
}
13 changes: 13 additions & 0 deletions tests/pos/i7087.scala
Original file line number Diff line number Diff line change
@@ -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