Dotty Documentation

0.11.0-bin-SNAPSHOT

trait Dynamic
extends Object

Handles programmable member selections of Dynamic instances and values with structural types. Two functionalities:

  1. 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.

  1. Translates member selections on structural types to calls of selectDynamic or applyDynamic on a Selectable instance. @See handleStructural.

[-] Constructors

[-] Members

[+] private def coreDynamic ( qual: Tree , dynName: Name , name: Name , selPos: Position , targs: List [ Tree ] ) ( implicit ctx: Context ) : Apply
[+] def handleStructural ( tree: Tree ) ( implicit ctx: Context ) : Tree

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:

(x: Selectable).selectDynamic("a").asInstanceOf[U]

Given x.a(a11, ..., a1n)...(aN1, ..., aNn), where x.a is of (widened) type (T11, ..., T1n)...(TN1, ..., TNn) => R, it is desugared to:

(x:selectable).applyDynamic("a", CT11, ..., CT1n, ..., CTN1, ... CTNn)
                           (a11, ..., a1n, ..., aN1, ..., aNn)
              .asInstanceOf[R]

where CT11, ..., CTNn are the class tags representing the erasure of T11, ..., TNn.

It's an error if U is neither a value nor a method type, or a dependent method type.

[+] def typedDynamicApply ( tree: Apply , pt: Type ) ( implicit ctx: Context ) : Tree

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), ...)

[+] def typedDynamicAssign ( tree: Assign , pt: Type ) ( implicit ctx: Context ) : Tree

Translate selection that does not typecheck according to the normal rules into a updateDynamic. foo.bar = baz ~~> foo.updateDynamic(bar)(baz)

[+] def typedDynamicSelect ( tree: Select , targs: List [ Tree ] , pt: Type ) ( implicit ctx: Context ) : Tree

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)].