Skip to content
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

Merged
merged 1 commit into from
Aug 10, 2022
Merged

Conversation

RazvanN7
Copy link
Contributor

No description provided.

@@ -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)))
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RazvanN7

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.

https://forum.dlang.org/post/k6o04g$259s$1@digitalmars.com

@RazvanN7 RazvanN7 merged commit 46e5cb5 into dlang:master Aug 10, 2022
RazvanN7 added a commit to RazvanN7/dlang.org that referenced this pull request Aug 12, 2022
RazvanN7 added a commit to RazvanN7/dlang.org that referenced this pull request Aug 12, 2022
dlang-bot pushed a commit that referenced this pull request Aug 15, 2022
devmynote pushed a commit to devmynote/dlang.org that referenced this pull request Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants