View source code
Display the source code in dmd/mtype.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function dmd.mtype.isRecursiveAliasThis

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

bool isRecursiveAliasThis (
  ref Type att,
  Type t
);

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

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

Returns

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

Authors

Walter Bright

License

Boost License 1.0