[Issue 11080] assert(`string`) should be forbidden

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Sep 23 05:19:59 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11080



--- Comment #25 from monarchdodra at gmail.com 2013-09-23 05:19:57 PDT ---
(In reply to comment #17)
> (In reply to comment #12)
> > (In reply to comment #11)
> > > Assert("string") is a bug. There should be no discussion here.
> > 
> > Why is it a bug? That's the discussion we're having. An array literal that
> > evaluates to null *will* trigger it. A user can test it.
> > 
> > void main()
> > {
> >     enum string s1 = "string";
> >     enum string s2 = null;
> > 
> >     assert( s1);
> >     assert(!s2);
> > 
> >     assert( "");
> >     assert(!string.init);
> > }
> > 
> > These all seem like legit use cases to me.
> 
> No, there is difference between array type object and array literal expression.
> Code like assert("Array literal") (note that this is not assert(s) where 's'
> refers to a string) is always a bug because the expression is always true and
> indicates that user actually wanted assert(some_condition, "array literal").
> There is no reason to write such code. As I have pointed out above, even in
> situations which are not surely error, dmd still aborts compilation. In this
> regard discussed issue is clear because there is no doubt whether use case is a
> bug or not.

Fine.

But in that case, as a variation of 4733, we could simply ban *any* "implicit
call to explicit conversion to bool" for *all* array literals, regardless of
type and context? It would be a step in the right direction (IMO), be more
generic, and cover other "most probably wrong" use cases. EG:

if ("hello"){}
assert([1, 2, 3]);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list