PR: dlang/dmd#16161
The member of operator, is an operator that operates on a contextual type with respect to a given statement, declaration or expression.
It may appear as the first term in an expression, then it may be followed with binary and dot expressions.
The syntax of the operator is ':' Identifier
.
It is commonly implemented by doing a rewrite to: context.Identifier
. Where the context is a type which was provided by the usage syntax.
The type that the member of operator results in is the same as the one it is in context of.
If it does not match, it will error.
- Return expressions
The compiler rewrites
return :Identifier;
asreturn typeof(return).Identifier;
. - Variable declarations
Type qualifiers may not appear as the variable type, there must be a concrete type.
It can be thought of as the type on the variable as having been aliased with the alias applying to the variable type and as the context.
Type var = :Identifier;
would internally be rewritten as__Alias var = __Alias.Identifier;
. - Switch statements
The expression used by the switch statement, will need to be aliased as per variable declarations.
So
would be rewritten as
switch(expr) { case :Identifier: break; }
alias __Alias = typeof(expr); switch(expr) { case __Alias.Identifier: break; }
- Function calls
During parameter to argument matching, a check to see if the
typeof(param).Identifier
is possible forfunc(:Identifier)
. - Function parameter default initialization
It must support the default initialization of a parameter.
void func(Enum e = :Start)
. - Comparison
The left hand side type of a comparison is used as the context for the right hand side
e == :Start
. This may require an intermediary variable to get the type of, prior to the comparison.