Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

LinqJsEnumerables acting up when being evaluated in more than one context #4

Open
ProdigySim opened this issue Aug 29, 2014 · 3 comments

Comments

@ProdigySim
Copy link
Contributor

LinqJS enumerables (arrays wrapped by Enumerable.from()) seem to have problems in evaluation while they are being evaluated in another context. My apologies for the vague title here, but I'm not completely sure what the exact problem is.

Here's some simple Javascript test cases demonstrating odd behavior

var arr = [2,3]
var enm = Enumerable.from(arr);

// Expected: true; Actual: false;
enm.sequenceEqual(enm); 

// Expcted: [2, 3, 2, 3];  Actual: [2,3];
enm.selectMany(function(x) { return enm; }).toArray()

If we replace all uses of enm with Enumerable.from(enm) the issue persists.

If we replace all uses of enm with Enumerable.from(arr) we get the expected behavior without issue.

I can provide examples demonstrating how we can end up in scenarios like this from C# code, but in the interest of brevity I'll hold off for now.

@erik-kallen
Copy link
Contributor

Any chance you can create a pure JS repro and file a bug to Linq.js?

@ProdigySim
Copy link
Contributor Author

For some reason I didn't realize that linq.js was from another existing project. Heh.

I just tested against their 3.0.4-beta6, 3.0.3-b4 (as far as I could tell from their source control) and their 2.2.0.2 release and got no repro. There seems to be an issue with the Saltarelle modifications.

FWIW, you can test this issue by simply including mscorlib.js and this project's linq.js in the page and running the Javascript repro I provided in console.

@ProdigySim
Copy link
Contributor Author

I think I've found the source of the issue...

linq.js Line 300:

The variable var enumerator; is defined in a scope such that it's shared by all IEnumerators produced by the Enumerable. I can briefly confirm that moving the variable declaration to the anonymous function being passed into new Enumerable() fixes the issue.

I should be able to come up with tests and a pull request.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants