# dmd.aliasthis

Implements the `alias this` symbol.

Specification: Alias This

#### Authors

Walter Bright

#### License

Boost License 1.0

Source: aliasthis.d

Documentation: https://dlang.org/phobos/dmd_aliasthis.html

Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/aliasthis.d

- `AliasThis`

  #### Declaration

  `class `AliasThis`: dmd.dsymbol.Dsymbol;`

  alias ident this;

  - `sym`

    #### Declaration

    `Dsymbol `sym`;`

    The symbol this `alias this` resolves to

  - `isDeprecated_`

    #### Declaration

    `bool `isDeprecated_`;`

    Whether this `alias this` is deprecated or not

- `resolveAliasThis`

  #### Declaration

  `Expression `resolveAliasThis`(Scope* `sc`, Expression `e`, bool `gag` = false, bool `findOnly` = false);`

  Find the `alias this` symbol of `e`'s type.

  #### Parameters

  `Scope* `sc`` | context
  `Expression `e`` | expression forming the `this`
  `bool `gag`` | do not print errors, return `null` instead
  `bool `findOnly`` | don't do further processing like resolving properties, i.`e`. just return plain dotExp() result.

  #### Return Value

  Expression that is ``e`.aliasthis`

- `checkDeprecatedAliasThis`

  #### Declaration

  `bool `checkDeprecatedAliasThis`(AliasThis `at`, const ref Loc `loc`, Scope* `sc`);`

  Check if an `alias this` is deprecated

  #### Discussion

  Usually one would use `expression.checkDeprecated(scope, aliasthis)` to check if `expression` uses a deprecated `aliasthis`, but this calls `toPrettyChars` which lead to the following message: "Deprecation: alias this `fullyqualified.aggregate.__anonymous` is deprecated"

  #### Parameters

  `AliasThis `at`` | The `AliasThis` object to check
  `Loc `loc`` | `Loc` of the expression triggering the access to ``at``
  `Scope* `sc`` | `Scope` of the expression (deprecations do not trigger in deprecated scopes)

  #### Return Value

  Whether the alias this was reported as deprecated.

- `isRecursiveAliasThis`

  #### Declaration

  `bool `isRecursiveAliasThis`(ref Type `att`, Type `t`);`

  Check and set '`att`' if '`t`' is a recursive 'alias this' type

  #### Discussion

  The goal is to prevent endless loops when there is a cycle in the alias this chain. Since there is no multiple `alias this`, the chain either ends in a leaf, or it loops back on itself as some point.

  Example: S0 -> (S1 -> S2 -> S3 -> S1)
  `S0` is not a recursive alias this, so this returns `false`, and a rewrite to `S1` can be tried. `S1` is a recursive alias this type, but since ``att`` is initialized to `null`, this still returns `false`, but `att1` is set to `S1`. A rewrite to `S2` and `S3` can be tried, but when we want to try a rewrite to `S1` again, we notice ``att` == `t``, so we're back at the start of the loop, and this returns `true`.

  #### Parameters

  `Type `att`` | type reference used to detect recursion. Should be initialized to `null`.
  `Type `t`` | type of 'alias this' rewrite to attempt

  #### Return Value

  `false` if the rewrite is safe, `true` if it would loop back around