diff options
author | Martin Odersky <odersky@gmail.com> | 2007-02-23 17:28:51 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2007-02-23 17:28:51 +0000 |
commit | c90bd2b598fc8c0b9f66f8827751aa967da7401d (patch) | |
tree | 638bec641133043260b64bcaad5bf12b9d8a274e /src | |
parent | fca1d7499a02cee13c6845cb3cffe77c8dc73231 (diff) | |
download | scala-c90bd2b598fc8c0b9f66f8827751aa967da7401d.tar.gz scala-c90bd2b598fc8c0b9f66f8827751aa967da7401d.tar.bz2 scala-c90bd2b598fc8c0b9f66f8827751aa967da7401d.zip |
small corrections for duck typing
Diffstat (limited to 'src')
5 files changed, 30 insertions, 27 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala index 794a86594d..7abb358c45 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala @@ -335,7 +335,7 @@ abstract class TreeBrowsers { case Apply(fun, args) => ("Apply", EMPTY) - case ApplyDynamic(fun, args) => + case ApplyDynamic(qual, args) => ("Apply", EMPTY) case Super(qualif, mix) => @@ -485,8 +485,8 @@ abstract class TreeBrowsers { case Apply(fun, args) => List(fun) ::: args - case ApplyDynamic(fun, args) => - List(fun) ::: args + case ApplyDynamic(qual, args) => + List(qual) ::: args case Super(qualif, mix) => Nil diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala index e47e838722..28634815a6 100644 --- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala +++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala @@ -262,8 +262,8 @@ abstract class TreePrinters { case Apply(fun, vargs) => print(fun); printRow(vargs, "(", ", ", ")") - case ApplyDynamic(fun, vargs) => - print("<apply-dynamic>("); print(fun); print("#"); print(tree.symbol.nameString) + case ApplyDynamic(qual, vargs) => + print("<apply-dynamic>("); print(qual); print("#"); print(tree.symbol.nameString) printRow(vargs, ", (", ", ", "))") case Super(qual, mix) => diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index c7c376ad96..0eac9da0c7 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -598,8 +598,13 @@ trait Trees requires Global { override def symbol_=(sym: Symbol): unit = { fun.symbol = sym } } - /** Dynamic value application */ - case class ApplyDynamic(fun: Tree, args: List[Tree]) + /** Dynamic value application. + * In a dynamic application q.f(as) + * - q is stored in qual + * - as is stored in args + * - f is stored as the node's symbol field. + */ + case class ApplyDynamic(qual: Tree, args: List[Tree]) extends TermTree with SymTree /** Super reference */ @@ -731,7 +736,7 @@ trait Trees requires Global { case Typed(expr, tpt) => (eliminated by erasure) case TypeApply(fun, args) => case Apply(fun, args) => - case ApplyDynamic(fun, args) (introduced by erasure, eliminated by cleanup) + case ApplyDynamic(qual, args) (introduced by erasure, eliminated by cleanup) case Super(qual, mix) => case This(qual) => case Select(qualifier, selector) => @@ -779,7 +784,7 @@ trait Trees requires Global { def Typed(tree: Tree, expr: Tree, tpt: Tree): Typed def TypeApply(tree: Tree, fun: Tree, args: List[Tree]): TypeApply def Apply(tree: Tree, fun: Tree, args: List[Tree]): Apply - def ApplyDynamic(tree: Tree, fun: Tree, args: List[Tree]): ApplyDynamic + def ApplyDynamic(tree: Tree, qual: Tree, args: List[Tree]): ApplyDynamic def Super(tree: Tree, qual: Name, mix: Name): Super def This(tree: Tree, qual: Name): This def Select(tree: Tree, qualifier: Tree, selector: Name): Select @@ -858,8 +863,8 @@ trait Trees requires Global { new TypeApply(fun, args).copyAttrs(tree) def Apply(tree: Tree, fun: Tree, args: List[Tree]) = new Apply(fun, args).copyAttrs(tree) - def ApplyDynamic(tree: Tree, fun: Tree, args: List[Tree]) = - new ApplyDynamic(fun, args).copyAttrs(tree) + def ApplyDynamic(tree: Tree, qual: Tree, args: List[Tree]) = + new ApplyDynamic(qual, args).copyAttrs(tree) def Super(tree: Tree, qual: Name, mix: Name) = new Super(qual, mix).copyAttrs(tree) def This(tree: Tree, qual: Name) = @@ -1046,10 +1051,10 @@ trait Trees requires Global { if (fun0 == fun) && (args0 == args) => t case _ => copy.Apply(tree, fun, args) } - def ApplyDynamic(tree: Tree, fun: Tree, args: List[Tree]) = tree match { - case t @ ApplyDynamic(fun0, args0) - if (fun0 == fun) && (args0 == args) => t - case _ => copy.ApplyDynamic(tree, fun, args) + def ApplyDynamic(tree: Tree, qual: Tree, args: List[Tree]) = tree match { + case t @ ApplyDynamic(qual0, args0) + if (qual0 == qual) && (args0 == args) => t + case _ => copy.ApplyDynamic(tree, qual, args) } def Super(tree: Tree, qual: Name, mix: Name) = tree match { case t @ Super(qual0, mix0) @@ -1208,8 +1213,8 @@ trait Trees requires Global { copy.TypeApply(tree, transform(fun), transformTrees(args)) case Apply(fun, args) => copy.Apply(tree, transform(fun), transformTrees(args)) - case ApplyDynamic(fun, args) => - copy.ApplyDynamic(tree, transform(fun), transformTrees(args)) + case ApplyDynamic(qual, args) => + copy.ApplyDynamic(tree, transform(qual), transformTrees(args)) case Super(qual, mix) => copy.Super(tree, qual, mix) case This(qual) => @@ -1356,8 +1361,8 @@ trait Trees requires Global { traverse(fun); traverseTrees(args) case Apply(fun, args) => traverse(fun); traverseTrees(args) - case ApplyDynamic(fun, args) => - traverse(fun); traverseTrees(args) + case ApplyDynamic(qual, args) => + traverse(qual); traverseTrees(args) case Super(_, _) => ; case This(_) => diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index c75a5b460b..4809882041 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -461,14 +461,7 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer { /** A replacement for the standard typer's `typed1' method */ override protected def typed1(tree: Tree, mode: int, pt: Type): Tree = { var tree1 = try { - tree match { - case ApplyDynamic(fun, args) => - val fun1 = typed(fun, AnyRefClass.tpe) - val args1 = List.mapConserve(args)(arg => typed(arg, AnyRefClass.tpe)) - copy.ApplyDynamic(tree, fun1, args1) setType AnyRefClass.tpe - case _ => - super.typed1(adaptMember(tree), mode, pt) - } + super.typed1(adaptMember(tree), mode, pt) } catch { case ex: Throwable => //if (settings.debug.value) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 136954a7af..eca7e4bdef 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2249,6 +2249,11 @@ trait Typers requires Analyzer { } } + case ApplyDynamic(qual, args) => + val qual1 = typed(qual, AnyRefClass.tpe) + val args1 = List.mapConserve(args)(arg => typed(arg, AnyRefClass.tpe)) + copy.ApplyDynamic(tree, qual1, args1) setType AnyRefClass.tpe + case Super(qual, mix) => val (clazz, selftype) = if (tree.symbol != NoSymbol) { |