www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - continue identifier; on foreach broken for opApply

reply "Chris Miller" <chris dprogramming.com> writes:
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.
Feb 16 2006
next sibling parent reply "Chris Miller" <chris dprogramming.com> writes:
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.
Feb 16 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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 -----BEGIN PGP SIGNATURE----- iD8DBQFD9uOy3w+/yD4P9tIRAmFqAJ9RcItGFGcLwYPtOWCyCQpJ8D2m9QCePjcv DFkRWnYRGk+d21JBMV+wPpk= =QIZ4 -----END PGP SIGNATURE-----
Feb 18 2006
prev sibling next sibling parent reply BCS <BCS_member pathlink.com> writes:
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.
Feb 16 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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 -----BEGIN PGP SIGNATURE----- iD8DBQFD9uG93w+/yD4P9tIRAhRBAJ0QFCYicp0z6eoTlycXBHaH/VzYrgCfTGzx gB4ExheJPejjq9b3mXA8CD8= =MBKP -----END PGP SIGNATURE-----
Feb 18 2006
prev sibling parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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 -----BEGIN PGP SIGNATURE----- iD8DBQFD9uEU3w+/yD4P9tIRAmHRAKC5LltjUjCtynayXNAQRHsyA5vsTQCfS1PQ rCgJHCekkO6SU6BZoMoUKiU= =bC/I -----END PGP SIGNATURE-----
Feb 18 2006