Difference between "can call" and "can compile"

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Sep 8 19:58:23 UTC 2020


On Tue, Sep 08, 2020 at 07:48:36PM +0000, Paul Backus via Digitalmars-d wrote:
[...]
> writeln could just as easily use __traits(hasMember) to check for the
> presence of toString, and print a warning message if it exists but
> doesn't compile. In other words, the problem here is that writeln
> assumes "toString doesn't compile" implies "toString isn't supposed to
> compile," which in most cases is not actually true. Adding a new
> language feature is neither necessary nor sufficient to correct that
> assumption.
> 
> I agree that it would probably be a good idea to change writeln (and
> other similar code) so that it does not make these kinds of
> assumptions.
[...]

+1.  I think in the past, before the we had __traits(hasMember),
__traits(compiles) was used as a kind of poor man's substitute, based on
the shaky assumption that "it compiles" == "it has member X".  Now that
we have better ways of expressing this, we should get rid of
__traits(compiles) or other similar hacks based on similar shaky
assumptions.


T

-- 
Life begins when you can spend your spare time programming instead of watching television. -- Cal Keegan


More information about the Digitalmars-d mailing list