After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 660927 - lambda does not work correct with foreach statement
lambda does not work correct with foreach statement
Status: RESOLVED DUPLICATE of bug 628336
Product: vala
Classification: Core
Component: Code Generator
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2011-10-04 20:28 UTC by Peng Huang
Modified: 2011-10-04 20:33 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Peng Huang 2011-10-04 20:28:32 UTC
====== test.vala =======
delegate void P ();

void main(string[] argv)
{

  int[] numbers = {1,2,3};

  foreach (int i in numbers) {
    P p = () => {stdout.printf("%d %d\n", i, i * i);};
    p();
  }
}

The i in lambda function is always zero. It should be 1, 2, 3.
Comment 1 Luca Bruno 2011-10-04 20:33:10 UTC
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find.

Copy "i" into a local variable within the foreach block as a workaround.

*** This bug has been marked as a duplicate of bug 628336 ***