Deprecate implicit `int` to `bool` conversion for integer literals

Steven Schveighoffer schveiguy at yahoo.com
Tue Nov 14 13:17:22 UTC 2017


On 11/13/17 8:01 PM, Michael V. Franklin wrote:
> On Saturday, 11 November 2017 at 23:30:18 UTC, Andrei Alexandrescu wrote:
>> A DIP is necessary for all language changes. In this case a short and 
>> well-argued DIP seems to be the ticket. Walter and I spoke and such a 
>> proposal has a good chance to be successful.
> 
> Subject issues:
> https://issues.dlang.org/show_bug.cgi?id=9999
> https://issues.dlang.org/show_bug.cgi?id=10560
> 
> Spec in question:
> https://dlang.org/spec/type.html#bool
> 
> DIP:
> https://github.com/dlang/DIPs/pull/99
> 
> I need some feedback from the community before I move forward with the 
> DIP.  I'm torn between a few ideas and not sure how to proceed.
> 
> 1. Deprecate implicit conversion of integer literals to bool
> 2. Allow implicit conversion of integer literals to bool if a function 
> is not overloaded, but disallow it if the function is overloaded.
> 3. Change the overload resolution rules as illustrated in 
> https://github.com/dlang/dmd/pull/1942
> 
> If I had to choose one I would go with 1, simply because the implicit 
> conversion is janky and circumvents the type system for a mild-at-best 
> convenience.  But, it will cause breakage that needs to be managed.
> 
> 2 would solve the issues in question, but keep breakage at a minimum, 
> and would probably be preferred if users wish to maintain the status 
> quo.  Disadvantage is it's a special case to document, consider, and 
> explain.
> 
> 3 is similar to 2, and like 2, is a special case.
> 
> I don't even really have a dog in this fight, but the demonstration of 
> the problem in the bugzilla issues is simply embarrassing, and I'm tired 
> of seeing issues languish for so long in bugzilla without any resolution.
> 
> Is there any general consensus in the community on this issue so I can 
> be sure I'm fulfilling the community's preference?

My vote would be for 1. It's disruptive, but not that disruptive.

I almost always initialize a bool with true or false, not with 1 or 0.

The array handling is probably the only part that would be painful. but 
we could handle that the same way we deprecated octal numbers:

bools!"01001101"; => [false, true, false, false, true, true, false, true];

-Steve


More information about the Digitalmars-d mailing list