aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/typer/Inferencing.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-12-17 18:14:15 +0100
committerMartin Odersky <odersky@gmail.com>2016-12-17 18:14:15 +0100
commit0a07f7f3385e5cc65fe58db753d2781ecf14ec41 (patch)
tree7ca6b4df926eb0e1833949476d9e94f8698d06c2 /compiler/src/dotty/tools/dotc/typer/Inferencing.scala
parentd69e8490dc66f98719fa1483e57d824c3a61f99c (diff)
downloaddotty-0a07f7f3385e5cc65fe58db753d2781ecf14ec41.tar.gz
dotty-0a07f7f3385e5cc65fe58db753d2781ecf14ec41.tar.bz2
dotty-0a07f7f3385e5cc65fe58db753d2781ecf14ec41.zip
Infer type parameters of anonymous class parents from expected type
If a parent type of an anonymous class is an Ident or Select which refers to a parameterized type, use the expected type to infer its type parameters. Fixes #1803.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/typer/Inferencing.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Inferencing.scala12
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala
index 1cb86dd72..86649d78e 100644
--- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala
@@ -119,6 +119,18 @@ object Inferencing {
}
}
+ /** If `tree` has a PolyType, infer its type parameters by comparing with expected type `pt` */
+ def inferTypeParams(tree: Tree, pt: Type)(implicit ctx: Context): Tree = tree.tpe match {
+ case poly: PolyType =>
+ val (poly1, tvars) = constrained(poly, tree)
+ val tree1 = tree.withType(poly1).appliedToTypeTrees(tvars)
+ tree1.tpe <:< pt
+ fullyDefinedType(tree1.tpe, "template parent", tree.pos)
+ tree1
+ case _ =>
+ tree
+ }
+
/** The list of uninstantiated type variables bound by some prefix of type `T` which
* occur in at least one formal parameter type of a prefix application.
* Considered prefixes are: