@@ -11,6 +11,7 @@ import dotty.tools.dotc.core.Names.{Name, TermName}
11
11
import dotty .tools .dotc .core .StdNames ._
12
12
import dotty .tools .dotc .core .Types ._
13
13
import dotty .tools .dotc .core .Decorators ._
14
+ import util .Positions ._
14
15
import core .Symbols ._
15
16
import core .Definitions
16
17
import Inferencing ._
@@ -49,7 +50,7 @@ trait Dynamic { self: Typer with Applications =>
49
50
* foo.bar[T0, ...](x = bazX, y = bazY, baz, ...) ~~> foo.applyDynamicNamed[T0, ...]("bar")(("x", bazX), ("y", bazY), ("", baz), ...)
50
51
*/
51
52
def typedDynamicApply (tree : untpd.Apply , pt : Type )(implicit ctx : Context ): Tree = {
52
- def typedDynamicApply (qual : untpd.Tree , name : Name , targs : List [untpd.Tree ]): Tree = {
53
+ def typedDynamicApply (qual : untpd.Tree , name : Name , selPos : Position , targs : List [untpd.Tree ]): Tree = {
53
54
def isNamedArg (arg : untpd.Tree ): Boolean = arg match { case NamedArg (_, _) => true ; case _ => false }
54
55
val args = tree.args
55
56
val dynName = if (args.exists(isNamedArg)) nme.applyDynamicNamed else nme.applyDynamic
@@ -62,19 +63,19 @@ trait Dynamic { self: Typer with Applications =>
62
63
case arg => namedArgTuple(" " , arg)
63
64
}
64
65
val args1 = if (dynName == nme.applyDynamic) args else namedArgs
65
- typedApply(untpd.Apply (coreDynamic(qual, dynName, name, targs), args1), pt)
66
+ typedApply(untpd.Apply (coreDynamic(qual, dynName, name, selPos, targs), args1), pt)
66
67
}
67
68
}
68
69
69
70
tree.fun match {
70
- case Select (qual, name) if ! isDynamicMethod(name) =>
71
- typedDynamicApply(qual, name, Nil )
72
- case TypeApply (Select (qual, name), targs) if ! isDynamicMethod(name) =>
73
- typedDynamicApply(qual, name, targs)
71
+ case sel @ Select (qual, name) if ! isDynamicMethod(name) =>
72
+ typedDynamicApply(qual, name, sel.pos, Nil )
73
+ case TypeApply (sel @ Select (qual, name), targs) if ! isDynamicMethod(name) =>
74
+ typedDynamicApply(qual, name, sel.pos, targs)
74
75
case TypeApply (fun, targs) =>
75
- typedDynamicApply(fun, nme.apply, targs)
76
+ typedDynamicApply(fun, nme.apply, fun.pos, targs)
76
77
case fun =>
77
- typedDynamicApply(fun, nme.apply, Nil )
78
+ typedDynamicApply(fun, nme.apply, fun.pos, Nil )
78
79
}
79
80
}
80
81
@@ -86,26 +87,26 @@ trait Dynamic { self: Typer with Applications =>
86
87
* through an existing transformation of in typedAssign [foo.bar(baz) = quux ~~> foo.bar.update(baz, quux)].
87
88
*/
88
89
def typedDynamicSelect (tree : untpd.Select , targs : List [Tree ], pt : Type )(implicit ctx : Context ): Tree =
89
- typedApply(coreDynamic(tree.qualifier, nme.selectDynamic, tree.name, targs), pt)
90
+ typedApply(coreDynamic(tree.qualifier, nme.selectDynamic, tree.name, tree.pos, targs), pt)
90
91
91
92
/** Translate selection that does not typecheck according to the normal rules into a updateDynamic.
92
93
* foo.bar = baz ~~> foo.updateDynamic(bar)(baz)
93
94
*/
94
95
def typedDynamicAssign (tree : untpd.Assign , pt : Type )(implicit ctx : Context ): Tree = {
95
- def typedDynamicAssign (qual : untpd.Tree , name : Name , targs : List [untpd.Tree ]): Tree =
96
- typedApply(untpd.Apply (coreDynamic(qual, nme.updateDynamic, name, targs), tree.rhs), pt)
96
+ def typedDynamicAssign (qual : untpd.Tree , name : Name , selPos : Position , targs : List [untpd.Tree ]): Tree =
97
+ typedApply(untpd.Apply (coreDynamic(qual, nme.updateDynamic, name, selPos, targs), tree.rhs), pt)
97
98
tree.lhs match {
98
- case Select (qual, name) if ! isDynamicMethod(name) =>
99
- typedDynamicAssign(qual, name, Nil )
100
- case TypeApply (Select (qual, name), targs) if ! isDynamicMethod(name) =>
101
- typedDynamicAssign(qual, name, targs)
99
+ case sel @ Select (qual, name) if ! isDynamicMethod(name) =>
100
+ typedDynamicAssign(qual, name, sel.pos, Nil )
101
+ case TypeApply (sel @ Select (qual, name), targs) if ! isDynamicMethod(name) =>
102
+ typedDynamicAssign(qual, name, sel.pos, targs)
102
103
case _ =>
103
104
errorTree(tree, ReassignmentToVal (tree.lhs.symbol.name))
104
105
}
105
106
}
106
107
107
- private def coreDynamic (qual : untpd.Tree , dynName : Name , name : Name , targs : List [untpd.Tree ])(implicit ctx : Context ): untpd.Apply = {
108
- val select = untpd.Select (qual, dynName)
108
+ private def coreDynamic (qual : untpd.Tree , dynName : Name , name : Name , selPos : Position , targs : List [untpd.Tree ])(implicit ctx : Context ): untpd.Apply = {
109
+ val select = untpd.Select (qual, dynName).withPos(selPos)
109
110
val selectWithTypes =
110
111
if (targs.isEmpty) select
111
112
else untpd.TypeApply (select, targs)
@@ -134,7 +135,7 @@ trait Dynamic { self: Typer with Applications =>
134
135
def structuralCall (selectorName : TermName , formals : List [Tree ]) = {
135
136
val selectable = adapt(qual, defn.SelectableType )
136
137
val scall = untpd.Apply (
137
- untpd.TypedSplice (selectable.select(selectorName)),
138
+ untpd.TypedSplice (selectable.select(selectorName)).withPos(tree.pos) ,
138
139
(Literal (Constant (name.toString)) :: formals).map(untpd.TypedSplice (_)))
139
140
typed(scall)
140
141
}
0 commit comments