DIP 52 - Implicit conversions
Simen Kjærås
simen.kjaras at gmail.com
Wed Dec 11 07:39:08 PST 2013
On 2013-12-11 16:28, bearophile wrote:
> Simen Kjærås:
>
>> http://wiki.dlang.org/DIP52
>
>> However, given that this code compiles and works perfectly:
>>
>> void baz() {
>> import std.typecons;
>> Tuple!(int, int) a;
>> Tuple!(int, "x", int, "y") b;
>> a = b; // Implicit conversion to less specialized type.
>> b = a; // Implicit conversion to more specialized type.
>
> I think "b = a;" is an accepts-invalid bug.
I partly agree. I want this to compile:
Tuple!(int, "x", int, "y") bar() {
import std.typecons;
Tuple!(int, int) a;
return a;
}
And doing that without letting "b = a;" above compile seems
counterintuitive and an unnecessary complexity.
>> void foo(TaggedUnion!(float, string, int, MyStruct) arg) {}
>
> Do you mean Algebraic?
Since a rewrite of Algebraic, supporting more features than the current
version, is in progress, I chose to use a simple tagged union (which is
what the current Algebraic is, I suppose).
> Regarding the topic of implicit conversions, I propose to warn and then
> deprecate and then disallow the following two implicit casts, that only
> cause confusion, and are of no real utility:
>
> enum Foo { A, B }
> void main() {
> enum int i1 = 1;
> bool b1 = i1; // deprecate
> int i2 = Foo.A; // deprecate
> }
I agree, but feel that this is orthogonal to the DIP.
--
Simen
More information about the Digitalmars-d
mailing list