-
-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Issue 15286 - is(typeof(symbol)) #3357
Conversation
| @@ -2370,6 +2370,12 @@ $(GNAME TypeSpecialization): | |||
| compared against. | |||
| ) | |||
|
|
|||
| $(P $(I IsExpression)s may be used in conjunction with $(D typeof) to check | |||
| whether an expression is semantically correct. For example, $(D is(typeof(foo))) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"semantically correct" is currently a poorly defined term. Is cast(ubyte*)0xDEADBEEF semantically correct inside a @safe function? The spec for __traits(compiles, X) also uses "semantically correct" but I recall there being subtle differences between that and is(typeof(X)).
I suppose it's out of scope for this issue though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like "to check whether an expression type checks correctly" would be more accurate. Errors not related to type checking are not done here AIUI. Could also suggest __traits(compiles) for full semantic checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semantically correct is essentially the same thing type checking from a compilers perspective. However, type-checking is a compiler developer specific term, whereas "semantically correct" is much more friendly to the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semantically correct is essentially the same thing type checking from a compilers perspective
That is not true when the context affects whether it compiles:
int i;
void f() pure
{
pragma(msg, is(typeof(i++))); // true
pragma(msg, __traits(compiles, i++)); // false
}So the new docs are misleading that is(typeof(expr)) tests whether expr is semantically correct. Some semantic checks are skipped.
Also Don Clugston said in 2012:
It checks if the expression has a type. That's all.
No description provided.