Jump to page: 1 2
Thread overview
bug in compiles?
Apr 11, 2019
Alex
Apr 11, 2019
Alex
Apr 11, 2019
bauss
Apr 11, 2019
Alex
Apr 11, 2019
Mike Parker
Apr 11, 2019
Alex
Apr 12, 2019
Seb
Apr 12, 2019
Jacob Carlborg
Apr 12, 2019
Alex
April 11, 2019
The following code works when I comment out the static if

//static if (__traits(compiles, __traits(getAttributes, T)))
   static foreach(a;  __traits(getAttributes, T)) Attributes ~=


There seems to be absolutely no reason why this code would fail with the static if but pass without it but in the first case I get no attributes because the __traits compiles fails.



__traits(compiles, __traits(getAttributes, T))

vs

__traits(getAttributes, T)

How could it not compile in the first case and yet work in the foreach?

T is a local variable name passed to this code, which does generally return an
error when used in certain ways:


int x;

Code!x; // Basically the code at the top

if I try to do too much with x I get `cannot use local `x` as a parameter to a non-global template`. Usually when I try to pass T to another template I get this error.


But some things work. But I can't for the life of me understand why compiles is failing but the foreach loop is working.


The problem is that I am using compiles quite often and either I'm misusing it or it's got some bugs in it that worry me because maybe they are silently failing?

Note that I get no errors in my code and I do get the attributes so it is technically working.

It would be really nice to know why the compiles is failing, e.g.,

pragma(compilesmsg, __traits(getAttributes, T)) spits out the error.





April 11, 2019
On 4/11/19 2:13 PM, Alex wrote:
> The following code works when I comment out the static if
> 
> //static if (__traits(compiles, __traits(getAttributes, T)))
>     static foreach(a;  __traits(getAttributes, T)) Attributes ~=
> 
> 
> There seems to be absolutely no reason why this code would fail with the static if but pass without it but in the first case I get no attributes because the __traits compiles fails.
> 
> 
> 
> __traits(compiles, __traits(getAttributes, T))
> 
> vs
> 
> __traits(getAttributes, T)
> 
> How could it not compile in the first case and yet work in the foreach?

It should. Do you have a larger example? One that can be played with?

-Steve
April 11, 2019
On Thursday, 11 April 2019 at 18:13:48 UTC, Alex wrote:
> The following code works when I comment out the static if
>
> //static if (__traits(compiles, __traits(getAttributes, T)))
>    static foreach(a;  __traits(getAttributes, T)) Attributes ~=
>
>
> There seems to be absolutely no reason why this code would fail with the static if but pass without it but in the first case I get no attributes because the __traits compiles fails.
>
>
>
> __traits(compiles, __traits(getAttributes, T))
>
> vs
>
> __traits(getAttributes, T)
>
> How could it not compile in the first case and yet work in the foreach?
>
> T is a local variable name passed to this code, which does generally return an
> error when used in certain ways:
>
>
> int x;
>
> Code!x; // Basically the code at the top
>
> if I try to do too much with x I get `cannot use local `x` as a parameter to a non-global template`. Usually when I try to pass T to another template I get this error.
>
>
> But some things work. But I can't for the life of me understand why compiles is failing but the foreach loop is working.
>
>
> The problem is that I am using compiles quite often and either I'm misusing it or it's got some bugs in it that worry me because maybe they are silently failing?
>
> Note that I get no errors in my code and I do get the attributes so it is technically working.
>
> It would be really nice to know why the compiles is failing, e.g.,
>
> pragma(compilesmsg, __traits(getAttributes, T)) spits out the error.

Must be something else in your code because it works fine for me with this shortened example.

https://run.dlang.io/is/o8xESB
April 11, 2019
On Thursday, 11 April 2019 at 20:49:45 UTC, bauss wrote:
> On Thursday, 11 April 2019 at 18:13:48 UTC, Alex wrote:
>> The following code works when I comment out the static if
>>
>> //static if (__traits(compiles, __traits(getAttributes, T)))
>>    static foreach(a;  __traits(getAttributes, T)) Attributes ~=
>>
>>
>> There seems to be absolutely no reason why this code would fail with the static if but pass without it but in the first case I get no attributes because the __traits compiles fails.
>>
>>
>>
>> __traits(compiles, __traits(getAttributes, T))
>>
>> vs
>>
>> __traits(getAttributes, T)
>>
>> How could it not compile in the first case and yet work in the foreach?
>>
>> T is a local variable name passed to this code, which does generally return an
>> error when used in certain ways:
>>
>>
>> int x;
>>
>> Code!x; // Basically the code at the top
>>
>> if I try to do too much with x I get `cannot use local `x` as a parameter to a non-global template`. Usually when I try to pass T to another template I get this error.
>>
>>
>> But some things work. But I can't for the life of me understand why compiles is failing but the foreach loop is working.
>>
>>
>> The problem is that I am using compiles quite often and either I'm misusing it or it's got some bugs in it that worry me because maybe they are silently failing?
>>
>> Note that I get no errors in my code and I do get the attributes so it is technically working.
>>
>> It would be really nice to know why the compiles is failing, e.g.,
>>
>> pragma(compilesmsg, __traits(getAttributes, T)) spits out the error.
>
> Must be something else in your code because it works fine for me with this shortened example.
>
> https://run.dlang.io/is/o8xESB

Seriously? Do you think you have ESP? Your code isn't even close to was talking about ;/

Here is is updated that shows the error. You seem to fail to understand that it is impossible for it to be my code. There is no way the static if should fail yet the static foreach pass. They both go together, that is is the whole point of the static if, to make sure the foreach works, yet it says it doesn't work when it in fact does(as commenting out the line proves).



import std.stdio, std.traits, std.conv;


struct A(alias T)
{
    static void foo()
    {
		static if (__traits(compiles, __traits(getAttributes, T))) // Failing for some reason
		    static foreach(a;  __traits(getAttributes, T)) pragma(msg, to!string(a), "-", typeof(a).stringof);
    }
}

void main()
{
    @(3) int a;

    (A!a).foo();


}

April 11, 2019
On Thursday, 11 April 2019 at 19:42:05 UTC, Steven Schveighoffer wrote:
> On 4/11/19 2:13 PM, Alex wrote:
>> The following code works when I comment out the static if
>> 
>> //static if (__traits(compiles, __traits(getAttributes, T)))
>>     static foreach(a;  __traits(getAttributes, T)) Attributes ~=
>> 
>> 
>> There seems to be absolutely no reason why this code would fail with the static if but pass without it but in the first case I get no attributes because the __traits compiles fails.
>> 
>> 
>> 
>> __traits(compiles, __traits(getAttributes, T))
>> 
>> vs
>> 
>> __traits(getAttributes, T)
>> 
>> How could it not compile in the first case and yet work in the foreach?
>
> It should. Do you have a larger example? One that can be played with?
>
> -Steve

import std.stdio, std.traits, std.conv;


struct A(alias T)
{
    static void foo()
    {
		static if (__traits(compiles, __traits(getAttributes, T))) // Failing for some reason
		    static foreach(a;  __traits(getAttributes, T)) pragma(msg, to!string(a), "-", typeof(a).stringof);
    }
}

void main()
{
    @(3) int a;

    (A!a).foo();
}

Commenting out the static if allows the foreach to pass and everything works. The whole point of the static if is to let the foreach work.

Both are only dependent on

__traits(getAttributes, T)

So if that can't compile then how could the foreach work?

https://run.dlang.io/is/WlXCIZ


April 11, 2019
On Thursday, 11 April 2019 at 22:41:32 UTC, Alex wrote:

>
> Seriously? Do you think you have ESP? Your code isn't even close to was talking about ;/
>
> Here is is updated that shows the error. You seem to fail to understand that it is impossible for it to be my code.

If you continue to attack people who are trying to help you, the moderators will stop approving your posts. The hostility is unwelcome here. If the number of your posts that have not been approved didn’t serve as a warning, then this does.
April 11, 2019
On Thursday, 11 April 2019 at 23:04:46 UTC, Mike Parker wrote:
> On Thursday, 11 April 2019 at 22:41:32 UTC, Alex wrote:
>
>>
>> Seriously? Do you think you have ESP? Your code isn't even close to was talking about ;/
>>
>> Here is is updated that shows the error. You seem to fail to understand that it is impossible for it to be my code.
>
> If you continue to attack people who are trying to help you, the moderators will stop approving your posts. The hostility is unwelcome here. If the number of your posts that have not been approved didn’t serve as a warning, then this does.


Quick google search to help you with your problem:

https://www.quora.com/How-do-I-develop-a-thick-skin-and-stop-getting-offended-over-everything

https://www.arkansasonline.com/news/2019/feb/05/too-thin-skin-20190205/

https://medium.com/the-mission/welcome-to-the-thin-skinned-generation-where-everything-is-a-bloody-problem-8bd5cb336361

http://dare.wisc.edu/survey-results/1965-1970/emotional-states-and-attitudes/gg8

http://meanttobehappy.com/10-ways-you-too-can-stop-being-so-easily-offended/


You can't police the world. You seem to live in a PC fantasy world where where every little booboo is treated as a life and death situation. You are not helping with the world with your need to control it. What are you going to do when things get really bad in the world? Have a nervous break down? If you think the shit I say is hostile and attacking people you really have no clue what the real world is like. You seem to have control issues that you should get addressed if you are going to threaten people over moronic statements that you interpret with your bias to be hostile. I'm sorry, but I'm not going to play your games. Did you go after FeepingCreature? He was clearly more hostile than I was but I bet you didn't say a god damn thing to him... You want me to stop being "hostile" then you need to throw your badge in the trash and stop trying to police every conversation because you really are in no position to judge people objectively. This isn't a nursery school and we are not 3 year olds... and if you want to turn it in to that kinda atmosphere then you kiss my ass.



April 12, 2019
On Thursday, 11 April 2019 at 23:55:18 UTC, Alex wrote:

> to judge people objectively. This isn't a nursery school and we are not 3 year olds...

Exactly. So start behaving like a grown-up and professional.

When you ask someone for help on the street, do you curse at him too?
April 11, 2019
On 4/11/19 6:45 PM, Alex wrote:
> On Thursday, 11 April 2019 at 19:42:05 UTC, Steven Schveighoffer wrote:
>> On 4/11/19 2:13 PM, Alex wrote:
>>> The following code works when I comment out the static if
>>>
>>> //static if (__traits(compiles, __traits(getAttributes, T)))
>>>     static foreach(a;  __traits(getAttributes, T)) Attributes ~=
>>>
>>>
>>> There seems to be absolutely no reason why this code would fail with the static if but pass without it but in the first case I get no attributes because the __traits compiles fails.
>>>
>>>
>>>
>>> __traits(compiles, __traits(getAttributes, T))
>>>
>>> vs
>>>
>>> __traits(getAttributes, T)
>>>
>>> How could it not compile in the first case and yet work in the foreach?
>>
>> It should. Do you have a larger example? One that can be played with?
>>
>> -Steve
> 
> import std.stdio, std.traits, std.conv;
> 
> 
> struct A(alias T)
> {
>      static void foo()
>      {
>          static if (__traits(compiles, __traits(getAttributes, T))) // Failing for some reason
>              static foreach(a;  __traits(getAttributes, T)) pragma(msg, to!string(a), "-", typeof(a).stringof);
>      }
> }
> 
> void main()
> {
>      @(3) int a;
> 
>      (A!a).foo();
> }
> 
> Commenting out the static if allows the foreach to pass and everything works. The whole point of the static if is to let the foreach work.
> 
> Both are only dependent on
> 
> __traits(getAttributes, T)
> 
> So if that can't compile then how could the foreach work?
> 
> https://run.dlang.io/is/WlXCIZ
> 
> 

Seems like a bug to me.

These all work:

@(3) int a;

static assert(__traits(compiles, __traits(getAttributes, a)));
alias X = a;
static assert(__traits(compiles, __traits(getAttributes, X)));

But this does not:

static function foo(alias T)()
{
   static assert(__traits(compiles, __traits(getAttributes, T)));
}

foo!a;

I think all 3 should work.

-Steve
April 12, 2019
On 2019-04-11 20:13, Alex wrote:
> The following code works when I comment out the static if
> 
> //static if (__traits(compiles, __traits(getAttributes, T)))
>     static foreach(a;  __traits(getAttributes, T)) Attributes ~=
> 
> 
> There seems to be absolutely no reason why this code would fail with the static if but pass without it but in the first case I get no attributes because the __traits compiles fails.
> 
> 
> 
> __traits(compiles, __traits(getAttributes, T))
> 
> vs
> 
> __traits(getAttributes, T)
> 
> How could it not compile in the first case and yet work in the foreach?

The problem is that "__traits(getAttributes, T)" in it self is not valid code. It needs to be part of larger expression or statement. The following seems to work:

https://run.dlang.io/is/JWkdbQ

-- 
/Jacob Carlborg
« First   ‹ Prev
1 2