Handles programmable member selections of Dynamic
instances and values
with structural types. Two functionalities:
- Translates selection that does not typecheck according to the scala.Dynamic rules: foo.bar(baz) = quux ~~> foo.selectDynamic(bar).update(baz, quux) foo.bar = baz ~~> foo.updateDynamic("bar")(baz) foo.bar(x = bazX, y = bazY, baz, ...) ~~> foo.applyDynamicNamed("bar")(("x", bazX), ("y", bazY), ("", baz), ...) foo.bar(baz0, baz1, ...) ~~> foo.applyDynamic(bar)(baz0, baz1, ...) foo.bar ~~> foo.selectDynamic(bar)
The first matching rule of is applied.
- Translates member selections on structural types to calls of
selectDynamic
orapplyDynamic
on aSelectable
instance. @See handleStructural.
- Companion:
- object
Value members
Concrete methods
Handle reflection-based dispatch for members of structural types.
Handle reflection-based dispatch for members of structural types.
Given x.a
, where x
is of (widened) type T
(a value type or a nullary method type),
and x.a
is of type U
, map x.a
to the equivalent of:
x1.selectDynamic("a").asInstanceOf[U]
where x1
is x
adapted to Selectable
.
Given x.a(a11, ..., a1n)...(aN1, ..., aNn)
, where x.a
is of (widened) type
(T11, ..., T1n)...(TN1, ..., TNn): R
, it is desugared to:
x1.applyDynamic("a")(a11, ..., a1n, ..., aN1, ..., aNn)
.asInstanceOf[R]
If this call resolves to an applyDynamic
method that takes a Class[?]*
as second
parameter, we further rewrite this call to
scala
x1.applyDynamic("a", c11, ..., c1n, ..., cN1, ... cNn)
(a11, ..., a1n, ..., aN1, ..., aNn)
.asInstanceOf[R]
where c11, ..., cNn are the classOf constants representing the erasures of T11, ..., TNn.
It's an error if U is neither a value nor a method type, or a dependent method type
Translate selection that does not typecheck according to the normal rules into a applyDynamic/applyDynamicNamed. foo.bar(baz0, baz1, ...) ~~> foo.applyDynamic(bar)(baz0, baz1, ...) foo.bar[T0, ...](baz0, baz1, ...) ~~> foo.applyDynamicT0, ...(baz0, baz1, ...) foo.bar(x = bazX, y = bazY, baz, ...) ~~> foo.applyDynamicNamed("bar")(("x", bazX), ("y", bazY), ("", baz), ...) foo.bar[T0, ...](x = bazX, y = bazY, baz, ...) ~~> foo.applyDynamicNamedT0, ...(("x", bazX), ("y", bazY), ("", baz), ...)
Translate selection that does not typecheck according to the normal rules into a applyDynamic/applyDynamicNamed. foo.bar(baz0, baz1, ...) ~~> foo.applyDynamic(bar)(baz0, baz1, ...) foo.bar[T0, ...](baz0, baz1, ...) ~~> foo.applyDynamicT0, ...(baz0, baz1, ...) foo.bar(x = bazX, y = bazY, baz, ...) ~~> foo.applyDynamicNamed("bar")(("x", bazX), ("y", bazY), ("", baz), ...) foo.bar[T0, ...](x = bazX, y = bazY, baz, ...) ~~> foo.applyDynamicNamedT0, ...(("x", bazX), ("y", bazY), ("", baz), ...)
Translate selection that does not typecheck according to the normal rules into a updateDynamic. foo.bar = baz ~~> foo.updateDynamic(bar)(baz)
Translate selection that does not typecheck according to the normal rules into a updateDynamic. foo.bar = baz ~~> foo.updateDynamic(bar)(baz)
Translate selection that does not typecheck according to the normal rules into a selectDynamic. foo.bar ~~> foo.selectDynamic(bar) foo.bar[T0, ...] ~~> foo.selectDynamicT0, ...
Translate selection that does not typecheck according to the normal rules into a selectDynamic. foo.bar ~~> foo.selectDynamic(bar) foo.bar[T0, ...] ~~> foo.selectDynamicT0, ...
Note: inner part of translation foo.bar(baz) = quux ~~> foo.selectDynamic(bar).update(baz, quux) is achieved through an existing transformation of in typedAssign [foo.bar(baz) = quux ~~> foo.bar.update(baz, quux)].