Dotty Documentation

0.2.0-bin-SNAPSHOT

trait Dynamic

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 selectDynamicMethod on a Selectable instance. @See handleStructural.

[-] Constructors

[-] Members

[+] private def coreDynamic ( qual: Tree , dynName: Name , name: Name , 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 and x.a is of type U:

If U is a value type, map x.a to the equivalent of:

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

If U is a method type (T1,...,Tn)R, map x.a to the equivalent of:

(x: Selectable).selectDynamicMethod("a", CT1, ..., CTn).asInstanceOf[(T1,...,Tn) => R]

where CT1,...,CTn are the class tags representing the erasure of T1,...,Tn.

It's an error if U is neither a value nor a method type, or a dependent method type, or of too large arity (limit is Definitions.MaxStructuralMethodArity).

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