aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/config/Printers.scala1
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala20
-rw-r--r--tests/pos/typers.scala21
3 files changed, 30 insertions, 12 deletions
diff --git a/src/dotty/tools/dotc/config/Printers.scala b/src/dotty/tools/dotc/config/Printers.scala
index 0e5565a21..ee1acb71e 100644
--- a/src/dotty/tools/dotc/config/Printers.scala
+++ b/src/dotty/tools/dotc/config/Printers.scala
@@ -17,5 +17,6 @@ object Printers {
val implicits: Printer = noPrinter
val unapp: Printer = noPrinter
val completions = noPrinter
+ val gadts = noPrinter
} \ No newline at end of file
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index f565e72c9..d35e5fa93 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -613,9 +613,18 @@ class Typer extends Namer with Applications with Implicits {
cpy.ValDef(param, param.mods, param.name, paramTpt, param.rhs)
}
- val resultTpt =
- if (isFullyDefined(protoResult, ForceDegree.none)) untpd.TypeTree(protoResult)
- else untpd.TypeTree()
+ // Define result type of closure as the expected type, thereby pushing
+ // down any implicit searches. We do this even if the expected type is not fully
+ // defined, which is a bit of a hack. But it's needed to make the following work
+ // (see typers.scala and printers/PlainPrinter.scala for examples).
+ //
+ // def double(x: Char): String = s"$x$x"
+ // "abc" flatMap double
+ //
+ val resultTpt = protoResult match {
+ case WildcardType(_) => untpd.TypeTree()
+ case _ => untpd.TypeTree(protoResult)
+ }
typed(desugar.makeClosure(inferredParams, fnBody, resultTpt), pt)
}
}
@@ -646,14 +655,15 @@ class Typer extends Namer with Applications with Implicits {
typed(desugar.makeCaseLambda(tree.cases) withPos tree.pos, pt)
case _ =>
val sel1 = typedExpr(tree.selector)
- val selType = fullyDefinedType(sel1.tpe, "pattern selector", tree.pos)
+ val selType = widenForMatchSelector(
+ fullyDefinedType(sel1.tpe, "pattern selector", tree.pos))
/** gadtSyms = "all type parameters of enclosing methods that appear
* non-variantly in the selector type" todo: should typevars
* which appear with variances +1 and -1 (in different
* places) be considered as well?
*/
- val gadtSyms: Set[Symbol] = {
+ val gadtSyms: Set[Symbol] = ctx.traceIndented(gadts, i"GADT syms of $selType") {
val accu = new TypeAccumulator[Set[Symbol]] {
def apply(tsyms: Set[Symbol], t: Type): Set[Symbol] = {
val tsyms1 = t match {
diff --git a/tests/pos/typers.scala b/tests/pos/typers.scala
index 4edd7c2be..cb3bbc590 100644
--- a/tests/pos/typers.scala
+++ b/tests/pos/typers.scala
@@ -7,15 +7,17 @@ object typers {
val names = List("a", "b", "c")
val ints = List(1, 2, 3)
-
- for ((name, n) <- (names, ints).zipped)
- println(name.length + n)
-
- val entries = Array("abc", "def")
- for ((x, i) <- entries.zipWithIndex)
- println(x)
+ object Inference {
+
+ for ((name, n) <- (names, ints).zipped)
+ println(name.length + n)
+
+ def double(x: Char): String = s"$x$x"
+ "abc" flatMap double
+
+ }
object Eta {
def fun(x: Int): Int = x + 1
@@ -128,6 +130,11 @@ object typers {
arr(i).charAt(0)
val x = new ArrayBuffer[String] // testing overloaded polymorphic constructors
+
+ val entries = Array("abc", "def")
+
+ for ((x, i) <- entries.zipWithIndex)
+ println(x)
}
object SeqExtractors {