Thread overview
continue identifier; on foreach broken for opApply
Feb 16, 2006
Chris Miller
Function pointer mishap
Feb 16, 2006
Chris Miller
Feb 18, 2006
Thomas Kuehne
Feb 16, 2006
BCS
Feb 18, 2006
Thomas Kuehne
Feb 18, 2006
Thomas Kuehne
February 16, 2006
struct MyStruct
{
   int opApply(int delegate(inout int i) dg)
   {
      return 0;
   }
}
MyStruct foo;

int main()
{
   label:
   foreach(int i; foo)
   {
      continue label; // Remove this and all is OK.
   }

   return 0;
}


DMD v0.147 output on Windows:

Internal error: s2ir.c 520


In my original code it output:

mystruct.d(42) Error: too many initializers for MyStruct

even though I had just enough initializers; it would output the Internal error if I removed some of the initializers.


Problem doesn't happen if you foreach on a char[] for example.
February 16, 2006
On Thu, 16 Feb 2006 12:21:25 -0500, Chris Miller <chris@dprogramming.com> wrote:

> In my original code it output:
>
> mystruct.d(42) Error: too many initializers for MyStruct
>
> even though I had just enough initializers; it would output the Internal error if I removed some of the initializers.


Actually, this part is unrelated to the original bug report. This is what caused it:

struct MyStruct
{
   void function() func1;
   void function() func2(); // Notice the accidental () after the name.
}
void myfunc() { }
MyStruct foo =
{
   &myfunc,
   //&myfunc // Works only if commented out / removed.
};


I know I made a mistake but I don't know what the compiler is thinking.
February 16, 2006
Chris Miller wrote:
> struct MyStruct
> {
>    int opApply(int delegate(inout int i) dg)
>    {
>       return 0;
>    }
> }
> MyStruct foo;
> 
> int main()
> {
>    label:
>    foreach(int i; foo)
>    {
>       continue label; // Remove this and all is OK.
>    }
> 
>    return 0;
> }
> 
> 
> DMD v0.147 output on Windows:
> 
> Internal error: s2ir.c 520
> 
> 
> In my original code it output:
> 
> mystruct.d(42) Error: too many initializers for MyStruct
> 
> even though I had just enough initializers; it would output the Internal  error if I removed some of the initializers.
> 
> 
> Problem doesn't happen if you foreach on a char[] for example.

this should be something like:

 struct MyStruct
 {
    int opApply(int delegate(inout int i) dg)
    {
       return dg(/* some int */);
    }
 }

see:
http://www.digitalmars.com/d/statement.html#foreach

I think that the return value of opApply is used to generate the continues.
February 18, 2006
Chris Miller schrieb am 2006-02-16:
> struct MyStruct
> {
>     int opApply(int delegate(inout int i) dg)
>     {
>        return 0;
>     }
> }
> MyStruct foo;
>
> int main()
> {
>     label:
>     foreach(int i; foo)
>     {
>        continue label; // Remove this and all is OK.
>     }
>
>     return 0;
> }
>
>
> DMD v0.147 output on Windows:
>
> Internal error: s2ir.c 520
>
>
> In my original code it output:
>
> mystruct.d(42) Error: too many initializers for MyStruct
>
> even though I had just enough initializers; it would output the Internal error if I removed some of the initializers.
>
>
> Problem doesn't happen if you foreach on a char[] for example.

Added to DStress as http://dstress.kuehne.cn/run/c/continue_04_A.d http://dstress.kuehne.cn/run/c/continue_04_B.d http://dstress.kuehne.cn/run/c/continue_04_C.d http://dstress.kuehne.cn/run/c/continue_04_D.d http://dstress.kuehne.cn/run/c/continue_04_E.d

Thomas


February 18, 2006
BCS schrieb am 2006-02-16:
> Chris Miller wrote:
>> struct MyStruct
>> {
>>    int opApply(int delegate(inout int i) dg)
>>    {
>>       return 0;
>>    }
>> }
>> MyStruct foo;
>> 
>> int main()
>> {
>>    label:
>>    foreach(int i; foo)
>>    {
>>       continue label; // Remove this and all is OK.
>>    }
>> 
>>    return 0;
>> }
>> 
>> 
>> DMD v0.147 output on Windows:
>> 
>> Internal error: s2ir.c 520
>> 
>> 
>> In my original code it output:
>> 
>> mystruct.d(42) Error: too many initializers for MyStruct
>> 
>> even though I had just enough initializers; it would output the Internal  error if I removed some of the initializers.
>> 
>> 
>> Problem doesn't happen if you foreach on a char[] for example.
>
> this should be something like:
>
>   struct MyStruct
>   {
>      int opApply(int delegate(inout int i) dg)
>      {
>         return dg(/* some int */);
>      }
>   }
>
> see:
> http://www.digitalmars.com/d/statement.html#foreach
>
> I think that the return value of opApply is used to generate the continues.

This can't be the cause: http://dstress.kuehne.cn/run/c/continue_04_B.d // Fail: continue label; http://dstress.kuehne.cn/run/c/continue_04_E.d // Pass: continue;

Thomas


February 18, 2006
Chris Miller schrieb am 2006-02-16:
> On Thu, 16 Feb 2006 12:21:25 -0500, Chris Miller <chris@dprogramming.com> wrote:
>
>> In my original code it output:
>>
>> mystruct.d(42) Error: too many initializers for MyStruct
>>
>> even though I had just enough initializers; it would output the Internal error if I removed some of the initializers.
>
>
> Actually, this part is unrelated to the original bug report. This is what caused it:
>
> struct MyStruct
> {
>     void function() func1;
>     void function() func2(); // Notice the accidental () after the name.
> }
> void myfunc() { }
> MyStruct foo =
> {
>     &myfunc,
>     //&myfunc // Works only if commented out / removed.
> };
>
>
> I know I made a mistake but I don't know what the compiler is thinking.

Added to DStress as http://dstress.kuehne.cn/nocompile/d/delegate_16.d http://dstress.kuehne.cn/nocompile/f/function_05.d

Thomas