www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - static foreach nogc

reply Exil <Exil gmall.com> writes:
Am I missing something or should this be able to compile? I don't 
know where it is even using ~=, is it used internally for ranges?

struct T
{
 nogc:

auto opBinary(string op, V)(auto ref const(V) vec) const
{
     // Error: cannot use operator ~= in  nogc delegate 
onlineapp.T.opBinary!("+", T).opBinary.__lambda2
     static foreach(i ; 0 .. 1)
     {
     }
     return this;
}
}

void main() {
     T a, b;
     T c = a + b;
}


https://run.dlang.io/is/JDXcJj
May 29 2019
next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
Bug report please. That shouldn't be happening.
May 29 2019
prev sibling next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2019-05-30 04:56, Exil wrote:
 
 Am I missing something or should this be able to compile? I don't know 
 where it is even using ~=, is it used internally for ranges?
 
 struct T
 {
  nogc:
 
 auto opBinary(string op, V)(auto ref const(V) vec) const
 {
      // Error: cannot use operator ~= in  nogc delegate 
 onlineapp.T.opBinary!("+", T).opBinary.__lambda2
      static foreach(i ; 0 .. 1)
      {
      }
      return this;
 }
 }
 
 void main() {
      T a, b;
      T c = a + b;
 }
 
 
 https://run.dlang.io/is/JDXcJj
Looks like there are two issues here: 1. That "static foreach" cannot be used in a nogc function 2. That the error message mentions "delegate", which are not in the source code -- /Jacob Carlborg
May 30 2019
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 30.05.19 17:02, Jacob Carlborg wrote:
 On 2019-05-30 04:56, Exil wrote:
 Am I missing something or should this be able to compile? I don't know 
 where it is even using ~=, is it used internally for ranges?

 struct T
 {
  nogc:

 auto opBinary(string op, V)(auto ref const(V) vec) const
 {
      // Error: cannot use operator ~= in  nogc delegate 
 onlineapp.T.opBinary!("+", T).opBinary.__lambda2
      static foreach(i ; 0 .. 1)
      {
      }
      return this;
 }
 }

 void main() {
      T a, b;
      T c = a + b;
 }


 https://run.dlang.io/is/JDXcJj
Looks like there are two issues here: 1. That "static foreach" cannot be used in a nogc function 2. That the error message mentions "delegate", which are not in the source code
The only issue here is that ` nogc:` applies to all nested functions, including delegates that are only used for CTFE.
May 30 2019
parent reply Jacob Carlborg <doob me.com> writes:
On 2019-05-30 17:29, Timon Gehr wrote:

 The only issue here is that ` nogc:` applies to all nested functions, 
 including delegates that are only used for CTFE.
You don't see it has a problem that the compiler mentions "delegate" in an error message but "delegate" doesn't exist in the source code? -- /Jacob Carlborg
Jun 04 2019
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 04.06.19 19:58, Jacob Carlborg wrote:
 On 2019-05-30 17:29, Timon Gehr wrote:
 
 The only issue here is that ` nogc:` applies to all nested functions, 
 including delegates that are only used for CTFE.
You don't see it has a problem that the compiler mentions "delegate" in an error message but "delegate" doesn't exist in the source code?
The problem is that there is an error message at all.
Jun 05 2019
prev sibling parent reply Dennis <dkorpel gmail.com> writes:
On Thursday, 30 May 2019 at 02:56:16 UTC, Exil wrote:
 Am I missing something or should this be able to compile?
It's a known bug: https://issues.dlang.org/show_bug.cgi?id=18439
May 30 2019
parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Thursday, 30 May 2019 at 15:11:31 UTC, Dennis wrote:
 On Thursday, 30 May 2019 at 02:56:16 UTC, Exil wrote:
 Am I missing something or should this be able to compile?
It's a known bug: https://issues.dlang.org/show_bug.cgi?id=18439
Fixed in https://github.com/dlang/dmd/pull/9922
May 30 2019
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 31.05.19 05:40, Nicholas Wilson wrote:
 On Thursday, 30 May 2019 at 15:11:31 UTC, Dennis wrote:
 On Thursday, 30 May 2019 at 02:56:16 UTC, Exil wrote:
 Am I missing something or should this be able to compile?
It's a known bug: https://issues.dlang.org/show_bug.cgi?id=18439
Fixed in https://github.com/dlang/dmd/pull/9922
Disgusting.
Jun 05 2019