Thread overview
static foreach not working with this
Jan 07, 2019
Michelle Long
Jan 07, 2019
Michelle Long
Jan 07, 2019
Alex
Jan 07, 2019
Michelle Long
Jan 07, 2019
Alex
January 07, 2019
static foreach(k, p; AliasSeq!(this, s))		
{{
    p.foo(); // Fails even if this line is removed
}}

this not known at compile time. replace s with this and it works! s is an argument which is also not known at compile time(generally).

Should work with this.

Just "simplifying"

this.foo();
s.foo();


(obviously more complex code)


January 07, 2019
On Monday, 7 January 2019 at 16:01:50 UTC, Michelle Long wrote:
> static foreach(k, p; AliasSeq!(this, s))		
> {{
>     p.foo(); // Fails even if this line is removed
> }}
>
> this not known at compile time. replace s with this and it works! s is an argument which is also not known at compile time(generally).
>
> Should work with this.
>
> Just "simplifying"
>
> this.foo();
> s.foo();
>
>
> (obviously more complex code)

static foreach(k, p; AliasSeq!(Alias!this, s))		
{{
    p.foo(); // Fails even if this line is removed
}}
January 07, 2019
On Monday, 7 January 2019 at 16:16:57 UTC, Michelle Long wrote:
> On Monday, 7 January 2019 at 16:01:50 UTC, Michelle Long wrote:
>> static foreach(k, p; AliasSeq!(this, s))		
>> {{
>>     p.foo(); // Fails even if this line is removed
>> }}
>>
>> this not known at compile time. replace s with this and it works! s is an argument which is also not known at compile time(generally).
>>
>> Should work with this.
>>
>> Just "simplifying"
>>
>> this.foo();
>> s.foo();
>>
>>
>> (obviously more complex code)
>
> static foreach(k, p; AliasSeq!(Alias!this, s))		
> {{
>     p.foo(); // Fails even if this line is removed
> }}

referring to
https://forum.dlang.org/post/aqypsijjvajybtqtmnwt@forum.dlang.org

Do you trying to do a recursive call from foo to itself?
January 07, 2019
On 1/7/19 11:16 AM, Michelle Long wrote:
> On Monday, 7 January 2019 at 16:01:50 UTC, Michelle Long wrote:
>> static foreach(k, p; AliasSeq!(this, s))
>> {{
>>     p.foo(); // Fails even if this line is removed
>> }}
>>
>> this not known at compile time. replace s with this and it works! s is an argument which is also not known at compile time(generally).
>>
>> Should work with this.
>>
>> Just "simplifying"
>>
>> this.foo();
>> s.foo();
>>
>>
>> (obviously more complex code)
> 
> static foreach(k, p; AliasSeq!(Alias!this, s))
> {{
>      p.foo(); // Fails even if this line is removed
> }}

To expand on Michelle's cryptic response, the second form (using `Alias!this` instead of `this`) DOES work!

I think this is a bug. If the latter works, the former should. Please file at issues.dlang.org with a complete example.

-Steve
January 07, 2019
On Monday, 7 January 2019 at 16:29:25 UTC, Alex wrote:
> On Monday, 7 January 2019 at 16:16:57 UTC, Michelle Long wrote:
>> On Monday, 7 January 2019 at 16:01:50 UTC, Michelle Long wrote:
>>> static foreach(k, p; AliasSeq!(this, s))		
>>> {{
>>>     p.foo(); // Fails even if this line is removed
>>> }}
>>>
>>> this not known at compile time. replace s with this and it works! s is an argument which is also not known at compile time(generally).
>>>
>>> Should work with this.
>>>
>>> Just "simplifying"
>>>
>>> this.foo();
>>> s.foo();
>>>
>>>
>>> (obviously more complex code)
>>
>> static foreach(k, p; AliasSeq!(Alias!this, s))		
>> {{
>>     p.foo(); // Fails even if this line is removed
>> }}
>
> referring to
> https://forum.dlang.org/post/aqypsijjvajybtqtmnwt@forum.dlang.org
>
> Do you trying to do a recursive call from foo to itself?

foo has nothing to do with it, as I said, removing it produces the same error['p.foo(); // Fails even if this line is removed']. I only put in something in the block because some blockhead would say something if there was nothing there like "Why are you even bothering with a static for each on an empty block? are you that stupid that you don't realize the compiler won't emit any code?".


January 07, 2019
On Monday, 7 January 2019 at 16:31:49 UTC, Steven Schveighoffer wrote:
> On 1/7/19 11:16 AM, Michelle Long wrote:
>> On Monday, 7 January 2019 at 16:01:50 UTC, Michelle Long wrote:
>>> [...]
>> 
>> static foreach(k, p; AliasSeq!(Alias!this, s))
>> {{
>>      p.foo(); // Fails even if this line is removed
>> }}
>
> To expand on Michelle's cryptic response, the second form (using `Alias!this` instead of `this`) DOES work!
>
> I think this is a bug. If the latter works, the former should. Please file at issues.dlang.org with a complete example.
>
> -Steve

Ah, yes.