aboutsummaryrefslogtreecommitdiff
path: root/src/dotty
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-08-28 18:26:13 +0200
committerMartin Odersky <odersky@gmail.com>2014-08-28 18:26:35 +0200
commitcdaa3a0249977bc2a9eb385fb840d62e01273f71 (patch)
treec6fe36e90309555fa583f12927a03765eba4a6fa /src/dotty
parent215f73f1f6b8b03b49bdab80fbbfcf4574203d2b (diff)
downloaddotty-cdaa3a0249977bc2a9eb385fb840d62e01273f71.tar.gz
dotty-cdaa3a0249977bc2a9eb385fb840d62e01273f71.tar.bz2
dotty-cdaa3a0249977bc2a9eb385fb840d62e01273f71.zip
Enabling primitive operations in ReTyper
The idea is that primitive operations do not have a symbol, but when applied have directly a MethodType. Such operations will be generated in Erasure for array ops. The patch allows retyping of such operations.
Diffstat (limited to 'src/dotty')
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala10
-rw-r--r--src/dotty/tools/dotc/typer/Checking.scala6
-rw-r--r--src/dotty/tools/dotc/typer/ReTyper.scala8
3 files changed, 17 insertions, 7 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index a126db1ad..ff465ea2f 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -476,10 +476,8 @@ trait Applications extends Compatibility { self: Typer =>
}
case _ =>
fun1.tpe match {
- case ErrorType =>
- tree.withType(ErrorType)
- case tp =>
- throw new Error(s"unexpected type.\n fun1 = $fun1,\n methPart(fun1) = ${methPart(fun1)},\n methPart(fun1).tpe = ${methPart(fun1).tpe},\n tpe = $tp")
+ case ErrorType => tree.withType(ErrorType)
+ case tp => handleUnexpectedFunType(tree, fun1)
}
}
}
@@ -515,6 +513,10 @@ trait Applications extends Compatibility { self: Typer =>
else realApply
}
+ /** Overridden in ReTyper to handle primitive operations that can be generated after erasure */
+ protected def handleUnexpectedFunType(tree: untpd.Apply, fun: Tree)(implicit ctx: Context): Tree =
+ throw new Error(s"unexpected type.\n fun = $fun,\n methPart(fun) = ${methPart(fun)},\n methPart(fun).tpe = ${methPart(fun).tpe},\n tpe = ${fun.tpe}")
+
def typedTypeApply(tree: untpd.TypeApply, pt: Type)(implicit ctx: Context): Tree = track("typedTypeApply") {
var typedArgs = tree.args mapconserve (typedType(_))
val typedFn = typedExpr(tree.fun, PolyProto(typedArgs.tpes, pt))
diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala
index 6ecfee4e3..ab6514507 100644
--- a/src/dotty/tools/dotc/typer/Checking.scala
+++ b/src/dotty/tools/dotc/typer/Checking.scala
@@ -213,9 +213,9 @@ trait Checking {
if (ctx.phase <= ctx.refchecksPhase) checkStable(tref.prefix, pos)
if (traitReq && !(tref.symbol is Trait)) ctx.error(d"$tref is not a trait", pos)
tp
- case _ =>
- ctx.error(d"$tp is not a class type", pos)
- defn.ObjectClass.typeRef
+ case _ =>
+ ctx.error(d"$tp is not a class type", pos)
+ defn.ObjectClass.typeRef
}
/** Check that a non-implicit parameter making up the first parameter section of an
diff --git a/src/dotty/tools/dotc/typer/ReTyper.scala b/src/dotty/tools/dotc/typer/ReTyper.scala
index 230788cc1..4014aa202 100644
--- a/src/dotty/tools/dotc/typer/ReTyper.scala
+++ b/src/dotty/tools/dotc/typer/ReTyper.scala
@@ -70,5 +70,13 @@ class ReTyper extends Typer {
override def encodeName(tree: untpd.NameTree)(implicit ctx: Context) = tree
+ override def handleUnexpectedFunType(tree: untpd.Apply, fun: Tree)(implicit ctx: Context): Tree = fun.tpe match {
+ case mt @ MethodType(_, formals) =>
+ val args: List[Tree] = tree.args.zipWithConserve(formals)(typedExpr(_, _)).asInstanceOf[List[Tree]]
+ assignType(untpd.cpy.Apply(tree)(fun, args), fun, args)
+ case _ =>
+ super.handleUnexpectedFunType(tree, fun)
+ }
+
override def checkVariance(tree: Tree)(implicit ctx: Context) = ()
} \ No newline at end of file