Skip to content

Fix #7392: Interpolate all wildcards in the resulttype of a closure #7396

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 3 commits into from
Oct 10, 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
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -833,12 +833,18 @@ class Typer extends Namer
case _: WildcardType => untpd.TypeTree()
case _ => untpd.TypeTree(tp)
}
def interpolateWildcards = new TypeMap {
def apply(t: Type): Type = t match
case WildcardType(bounds: TypeBounds) =>
newTypeVar(apply(bounds.orElse(TypeBounds.empty)).bounds)
case _ => mapOver(t)
}
pt.stripTypeVar.dealias match {
case pt1 if defn.isNonRefinedFunction(pt1) =>
// if expected parameter type(s) are wildcards, approximate from below.
// if expected result type is a wildcard, approximate from above.
// this can type the greatest set of admissible closures.
(pt1.argTypesLo.init, typeTree(pt1.argTypesHi.last))
(pt1.argTypesLo.init, typeTree(interpolateWildcards(pt1.argTypesHi.last)))
case SAMType(sam @ MethodTpe(_, formals, restpe)) =>
(formals,
if (sam.isResultDependent)
Expand Down Expand Up @@ -1900,7 +1906,6 @@ class Typer extends Namer
else tree1
}


def typedAsFunction(tree: untpd.PostfixOp, pt: Type)(implicit ctx: Context): Tree = {
val untpd.PostfixOp(qual, Ident(nme.WILDCARD)) = tree
val pt1 = if (defn.isFunctionType(pt)) pt else AnyFunctionProto
Expand Down
16 changes: 16 additions & 0 deletions tests/pos/i7392.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
object Test {

trait ZStream[-R, +E, +A]

object ZStream {
def empty: ZStream[Any, Nothing, Nothing] =
???
}

trait Gen[-R, +A](sample: ZStream[R, Nothing, A])

def fromIterable[R, A](
as: Iterable[A],
shrinker: (A => ZStream[R, Nothing, A]) = (_: A) => ZStream.empty
): Gen[R, A] = ???
}