is(x = module) vs. __traits(isModule, x)
Steven Schveighoffer
schveiguy at gmail.com
Wed Oct 7 18:46:07 UTC 2020
Someone on the discord chat brought this up:
We currently have 2 ways to check if a symbol is a module:
import std.stdio;
pragma(msg, is(std.stdio == module)); // true
pragma(msg, __traits(isModule, std.stdio)); // true
Why both? The first thing that struck me is that, std.stdio is NOT a
type. `is` specifically says it works with types. So that seems out of
place (indeed the documentation does not mention anything special about
this).
And then I looked up when they were added, thinking that maybe one
predates the other, and there is a reason it didn't handle all cases.
Wrong. They were both added in the *same PR* to mean the *same thing*:
https://github.com/dlang/dmd/pull/5290
Is there a reason we want to have both? Why did we want to muddy the
`is` waters?
I really think we should remove one of these, I would recommend removing
the `is` form, since it's the only exception to the rule that the
parameter must be a type.
BTW, same with packages:
is(std == package) == __traits(isPackage, std);
-Steve
More information about the Digitalmars-d
mailing list