June 17, 2020
On Wednesday, 17 June 2020 at 03:15:52 UTC, Stefan Koch wrote:
> On Wednesday, 17 June 2020 at 03:04:43 UTC, Avrina wrote:
>> On Wednesday, 17 June 2020 at 01:34:18 UTC, Stefan Koch wrote:
>>> On Wednesday, 17 June 2020 at 01:26:48 UTC, Andrei Alexandrescu wrote:
>>>> On 6/16/20 7:01 PM, Paul Backus wrote:
>>>>> I agree that this is a bug, but it is a bug in the design of the language itself, not the implementation.
>>>>
>>>> Is that a sort of a compile-time race condition? If that's the case, D should deem the program ill-formed with no diagnostic required.
>>>
>>> That is ......
>>> I lack the words.
>>> I must be misunderstanding.
>>>
>>> Are you saying that it is fine for D to act differently on code that used to compile fine,
>>> because we don't want to detect order-dependency issues?
>>>
>>> Please clearify.
>>
>> It's more than a order-dependency issue.
>>
>>   pragma(msg, Foo.tupleof.length); // prints 1
>>
>>   struct Foo {
>>  	int a;
>>
>>     static if(Foo.tupleof.length == 1) {
>>     	int b;
>>     }
>>     static if(Foo.tupleof.length == 2) {
>>     	int c;
>>     }
>>   }
>>
>>   pragma(msg, Foo.tupleof.length); // prints 1
>>
>>   void main() {
>>     writeln(Foo.tupleof.length); // prints 2
>>   }
>>
>>
>>
>> If you try to do the same thing with "Foo.sizeof == 4/8" in the `static if`'s you get a compile error. Some attempt was made to prevent this situation, but not much. It doesn't make sense to probe information that isn't known at the time, or cannot be known at any time in that scope. It is ill-formed.
>
> That's because of how pragma(msg) works.
>
> It's evaluated eagerly.
> If you put a pragma(msg), inside your static if body it should print 2.
>
> static if is supposed to be able to introduce declarations, if the code you posted qualifies as legitimately as ill-formed, I am afraid there is lots and lots of code. Which does classify as ill-formed.

It's illogical, the size of Foo changes because it is querying it for information before the structure is even defined. Yes I imagine there is probably a lot of code that compiles that shouldn't. There's probably a lot of silent bugs, and from time to time when D changes and the order the of the semantic changes, code that once did compile won't compile anymore because the code never made sense in the first place.


static assert(Foo.tupleof.length == 1);

struct Foo {
 	int a;

    static if(Foo.tupleof.length == 1) {
    	int b;
        static assert(Foo.tupleof.length == 3); // ok
    }

    static if(Foo.tupleof.length == 1) {
    	int c;
    }

    static assert(Foo.tupleof.length == 3); // ok
    static if(Foo.tupleof.length == 3) {
    	int d;
        static assert(0); // never run
    }
}

June 19, 2020
On Wednesday, 17 June 2020 at 16:08:41 UTC, Avrina wrote:
> On Wednesday, 17 June 2020 at 03:15:52 UTC, Stefan Koch wrote:
>> [...]
>
> It's illogical, the size of Foo changes because it is querying it for information before the structure is even defined. Yes I imagine there is probably a lot of code that compiles that shouldn't. There's probably a lot of silent bugs, and from time to time when D changes and the order the of the semantic changes, code that once did compile won't compile anymore because the code never made sense in the first place.
>
>
> static assert(Foo.tupleof.length == 1);
>
> struct Foo {
>  	int a;
>
>     static if(Foo.tupleof.length == 1) {
>     	int b;
>         static assert(Foo.tupleof.length == 3); // ok
>     }
>
>     static if(Foo.tupleof.length == 1) {
>     	int c;
>     }
>
>     static assert(Foo.tupleof.length == 3); // ok
>     static if(Foo.tupleof.length == 3) {
>     	int d;
>         static assert(0); // never run
>     }
> }

For all static if's the length to the tuple is 1.
For all static asserts the length of the tuple is 3.

You made it look more variant than it is.

What we have to do is to formalize the behavior.
June 19, 2020
On Friday, 19 June 2020 at 12:38:44 UTC, Stefan Koch wrote:
> On Wednesday, 17 June 2020 at 16:08:41 UTC, Avrina wrote:
>> On Wednesday, 17 June 2020 at 03:15:52 UTC, Stefan Koch wrote:
>>> [...]
>>
>> It's illogical, the size of Foo changes because it is querying it for information before the structure is even defined. Yes I imagine there is probably a lot of code that compiles that shouldn't. There's probably a lot of silent bugs, and from time to time when D changes and the order the of the semantic changes, code that once did compile won't compile anymore because the code never made sense in the first place.
>>
>>
>> static assert(Foo.tupleof.length == 1);
>>
>> struct Foo {
>>  	int a;
>>
>>     static if(Foo.tupleof.length == 1) {
>>     	int b;
>>         static assert(Foo.tupleof.length == 3); // ok
>>     }
>>
>>     static if(Foo.tupleof.length == 1) {
>>     	int c;
>>     }
>>
>>     static assert(Foo.tupleof.length == 3); // ok
>>     static if(Foo.tupleof.length == 3) {
>>     	int d;
>>         static assert(0); // never run
>>     }
>> }
>
> For all static if's the length to the tuple is 1.
> For all static asserts the length of the tuple is 3.
>
> You made it look more variant than it is.
>
> What we have to do is to formalize the behavior.

Not sure what you mean, it's wrong, just plain wrong, it doesn't matter if it's more or less wrong, it is still wrong.

Like I said, if you use Foo.sizeof, you get a compiler error. That's what it should be, a compiler error because it is ill-formed. It's wrong for the same reason this is wrong:


struct Foo {
    typeof(Foo.a) a;
}

It doesn't make sense. The compiler just allows incorrect logic. There's nothing to formalize to make it work in a way that makes sense.
1 2 3
Next ›   Last »