Re: Unexpected foreach lowering

2016-08-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, August 11, 2016 08:42:27 Steven Schveighoffer via Digitalmars-d- learn wrote: > On 8/11/16 12:28 AM, Jonathan M Davis via Digitalmars-d-learn wrote: > > On Wednesday, August 10, 2016 21:00:01 Lodovico Giaretta via > > Digitalmars-d- > > > > learn wrote: > >> Wow. Thanks. I didn't know

Re: Unexpected foreach lowering

2016-08-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/10/16 5:14 PM, ag0aep6g wrote: On 08/10/2016 10:54 PM, Steven Schveighoffer wrote: The issue is that it tries using [] on the item to see if it defines a range-like thing. Since you don't define opSlice(), it automatically goes to the subrange. This breaks for int[] as well as Array. If

Re: Unexpected foreach lowering

2016-08-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/11/16 12:28 AM, Jonathan M Davis via Digitalmars-d-learn wrote: On Wednesday, August 10, 2016 21:00:01 Lodovico Giaretta via Digitalmars-d- learn wrote: Wow. Thanks. I didn't know the compiler would try opSlice. I will file it. It does that so that you can use foreach with containers

Re: Unexpected foreach lowering

2016-08-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, August 10, 2016 21:00:01 Lodovico Giaretta via Digitalmars-d- learn wrote: > Wow. Thanks. I didn't know the compiler would try opSlice. I will > file it. It does that so that you can use foreach with containers without having to call something on the container. The idea is that the

Re: Unexpected foreach lowering

2016-08-10 Thread ag0aep6g via Digitalmars-d-learn
On 08/10/2016 10:54 PM, Steven Schveighoffer wrote: The issue is that it tries using [] on the item to see if it defines a range-like thing. Since you don't define opSlice(), it automatically goes to the subrange. This breaks for int[] as well as Array. If I add opSlice to your code (and

Re: Unexpected foreach lowering

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 21:00:01 UTC, Lodovico Giaretta wrote: On Wednesday, 10 August 2016 at 20:54:15 UTC, Steven Schveighoffer wrote: [...] Wow. Thanks. I didn't know the compiler would try opSlice. I will file it. Filed on bugzilla:

Re: Unexpected foreach lowering

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 20:54:15 UTC, Steven Schveighoffer wrote: On 8/10/16 2:08 PM, Lodovico Giaretta wrote: [...] The issue is that it tries using [] on the item to see if it defines a range-like thing. Since you don't define opSlice(), it automatically goes to the subrange.

Re: Unexpected foreach lowering

2016-08-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/10/16 2:08 PM, Lodovico Giaretta wrote: I'm probably missing something stupid but... Why on earth do the two loops in main print a different result? It looks like the foreach lowering is ignoring my definition of front... = import

Re: Unexpected foreach lowering

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 19:37:39 UTC, Ali Çehreli wrote: A quick read reveals popFront() is implemented only for bool Arrays. That explains the issue. I don't know whether it's an oversight. Ali First of all, thank you for spending your time on this issue. I really appreciate that.

Re: Unexpected foreach lowering

2016-08-10 Thread Ali Çehreli via Digitalmars-d-learn
On 08/10/2016 11:47 AM, Lodovico Giaretta wrote: On Wednesday, 10 August 2016 at 18:38:00 UTC, Ali Çehreli wrote: RangeWrapper does not provide the InputRange interface, so the compiler uses 'alias this' and iterates directly on the member range. I tried making RangeWrapper an InputRange but

Re: Unexpected foreach lowering

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 18:38:00 UTC, Ali Çehreli wrote: RangeWrapper does not provide the InputRange interface, so the compiler uses 'alias this' and iterates directly on the member range. I tried making RangeWrapper an InputRange but failed. It still uses 'range'. // Still fails

Re: Unexpected foreach lowering

2016-08-10 Thread Ali Çehreli via Digitalmars-d-learn
On 08/10/2016 11:08 AM, Lodovico Giaretta wrote: > I'm probably missing something stupid but... > Why on earth do the two loops in main print a different result? > It looks like the foreach lowering is ignoring my definition of front... > > = >

Re: Unexpected foreach lowering

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 18:08:02 UTC, Lodovico Giaretta wrote: I'm probably missing something stupid but... Why on earth do the two loops in main print a different result? It looks like the foreach lowering is ignoring my definition of front...

Unexpected foreach lowering

2016-08-10 Thread Lodovico Giaretta via Digitalmars-d-learn
I'm probably missing something stupid but... Why on earth do the two loops in main print a different result? It looks like the foreach lowering is ignoring my definition of front... = import std.stdio, std.container.array; struct