@@ -10,7 +10,6 @@ import dotty.tools.dotc.core.Contexts.Context
10
10
import dotty .tools .dotc .core .Names .Name
11
11
import dotty .tools .dotc .core .StdNames ._
12
12
import dotty .tools .dotc .core .Types ._
13
- import dotty .tools .dotc .core .Mode
14
13
import dotty .tools .dotc .core .Decorators ._
15
14
16
15
object Dynamic {
@@ -30,10 +29,12 @@ object Dynamic {
30
29
trait Dynamic { self : Typer with Applications =>
31
30
32
31
/** Translate selection that does not typecheck according to the normal rules into a applyDynamic/applyDynamicNamed.
33
- * foo.bar(baz0, baz1, ...) ~~> foo.applyDynamic(bar)(baz0, baz1, ...)
34
- * foo.bar(x = bazX, y = bazY, baz, ...) ~~> foo.applyDynamicNamed("bar")(("x", bazX), ("y", bazY), ("", baz), ...)
32
+ * foo.bar(baz0, baz1, ...) ~~> foo.applyDynamic(bar)(baz0, baz1, ...)
33
+ * foo.bar[T0, ...](baz0, baz1, ...) ~~> foo.applyDynamic[T0, ...](bar)(baz0, baz1, ...)
34
+ * foo.bar(x = bazX, y = bazY, baz, ...) ~~> foo.applyDynamicNamed("bar")(("x", bazX), ("y", bazY), ("", baz), ...)
35
+ * foo.bar[T0, ...](x = bazX, y = bazY, baz, ...) ~~> foo.applyDynamicNamed[T0, ...]("bar")(("x", bazX), ("y", bazY), ("", baz), ...)
35
36
*/
36
- def typedDynamicApply (qual : untpd.Tree , name : Name , args : List [untpd.Tree ], pt : Type )(original : untpd.Apply )(
37
+ def typedDynamicApply (qual : untpd.Tree , name : Name , targsOpt : Option [ List [untpd. Tree ]], args : List [untpd.Tree ], pt : Type )(original : untpd.Apply )(
37
38
implicit ctx : Context ): Tree = {
38
39
def isNamedArg (arg : untpd.Tree ): Boolean = arg match { case NamedArg (_, _) => true ; case _ => false }
39
40
val dynName = if (args.exists(isNamedArg)) nme.applyDynamicNamed else nme.applyDynamic
@@ -47,25 +48,32 @@ trait Dynamic { self: Typer with Applications =>
47
48
case arg => namedArgTuple(" " , arg)
48
49
}
49
50
val args1 = if (dynName == nme.applyDynamic) args else namedArgs
50
- typedApply(untpd.Apply (coreDynamic(qual, dynName, name), args1), pt)
51
+ typedApply(untpd.Apply (coreDynamic(qual, dynName, name, targsOpt ), args1), pt)
51
52
}
52
53
}
53
54
54
55
/** Translate selection that does not typecheck according to the normal rules into a selectDynamic.
55
- * foo.bar ~~> foo.selectDynamic(bar)
56
+ * foo.bar ~~> foo.selectDynamic(bar)
57
+ * foo.bar[T0, ...] ~~> foo.selectDynamic[T0, ...](bar)
56
58
*
57
59
* Note: inner part of translation foo.bar(baz) = quux ~~> foo.selectDynamic(bar).update(baz, quux) is achieved
58
60
* through an existing transformation of in typedAssign [foo.bar(baz) = quux ~~> foo.bar.update(baz, quux)].
59
61
*/
60
- def typedDynamicSelect (tree : untpd.Select , pt : Type )(implicit ctx : Context ): Tree =
61
- typedApply(coreDynamic(tree. qualifier, nme.selectDynamic, tree. name), pt)
62
+ def typedDynamicSelect (qualifier : untpd.Tree , name : Name , targsOpt : Option [ List [ Tree ]] , pt : Type )(implicit ctx : Context ): Tree =
63
+ typedApply(coreDynamic(qualifier, nme.selectDynamic, name, targsOpt ), pt)
62
64
63
65
/** Translate selection that does not typecheck according to the normal rules into a updateDynamic.
64
66
* foo.bar = baz ~~> foo.updateDynamic(bar)(baz)
65
67
*/
66
- def typedDynamicAssign (qual : untpd.Tree , name : Name , rhs : untpd.Tree , pt : Type )(implicit ctx : Context ): Tree =
67
- typedApply(untpd.Apply (coreDynamic(qual, nme.updateDynamic, name), rhs), pt)
68
+ def typedDynamicAssign (qual : untpd.Tree , name : Name , targsOpt : Option [ List [untpd. Tree ]], rhs : untpd.Tree , pt : Type )(implicit ctx : Context ): Tree =
69
+ typedApply(untpd.Apply (coreDynamic(qual, nme.updateDynamic, name, targsOpt ), rhs), pt)
68
70
69
- private def coreDynamic (qual : untpd.Tree , dynName : Name , name : Name )(implicit ctx : Context ): untpd.Apply =
70
- untpd.Apply (untpd.Select (qual, dynName), Literal (Constant (name.toString)))
71
+ private def coreDynamic (qual : untpd.Tree , dynName : Name , name : Name , targsOpt : Option [List [untpd.Tree ]])(implicit ctx : Context ): untpd.Apply = {
72
+ val select = untpd.Select (qual, dynName)
73
+ val selectWithTypes = targsOpt match {
74
+ case Some (targs) => untpd.TypeApply (select, targs)
75
+ case None => select
76
+ }
77
+ untpd.Apply (selectWithTypes, Literal (Constant (name.toString)))
78
+ }
71
79
}
0 commit comments