sq / JSIL

CIL to Javascript Compiler
http://jsil.org/
Other
1.73k stars 240 forks source link

Error "...has no method 'IEnumerable$b1_GetEnumerator" #133

Closed jwaynelee closed 11 years ago

jwaynelee commented 11 years ago

I'm just getting started with JSIL, and it looks very promising. My project is not a game, but is a number-crunching type of business app. I'm getting an error very early in the Javascript code created by JSIL. This is from the Chrome browser's developer tool:

CX~CX270~270.90~155.272180,CX~CX300~300.90~194.723400,CX~CX330~330.90~213.983700,CX~CX360~360.90~233.244000 has no method 'IEnumerable$b1_GetEnumerator'

(The string literal beginning with "CX" is a much shorter version of the actual string.)

My C# code looks like this:

IEnumerable Records;

Records = Belts.Split('^'); foreach (string Record in Records) { var Fields = Record.Split('~'); AllBelts.Add(new Belt(BeltTypeLookup[Fields[0]], Convert.ToDecimal(Fields[2]), Fields[1], Convert.ToDecimal(Fields[3]))); }

The Javascript code created by JSIL is this:

var Records = JSIL.SplitString(Belts, JSIL.Array.New($T0B(), ["^"])); var enumerator = Records.IEnumerable$b1_GetEnumerator(); try {

    while (enumerator.IEnumerator_MoveNext()) {
      var Record = enumerator.IEnumerator$b1_get_Current();
      var Fields = (JSIL.SplitString(Record, JSIL.Array.New($T0B(), ["~"])));
      this.AllBelts.Add(new ($T0F())(this.BeltTypeLookup.get_Item(Fields[0]), $sig.get(0x78D2, $asm01.System.Decimal, [$asm01.System.String], []).CallStatic($T10(), "ToDecimal", null, Fields[2]), Fields[1], $sig.get(0x78D2, $asm01.System.Decimal, [$asm01.System.String], []).CallStatic($T10(), "ToDecimal", null, Fields[3])));
    }
  } finally {
    if (enumerator !== null) {
      enumerator.IDisposable_Dispose();
    }
  }

The error "has no method 'IEnumerable$b1_GetEnumerator" occurs on the second line in the preceding Javascript code (the "var enumerator = " line.)

Thank you.

kg commented 11 years ago

FYI, Decimal support in JSIL is pretty minimal at present - it's emulated with doubles - so I wouldn't recommend using JSIL as-is for financial computations.

jwaynelee commented 11 years ago

Thank you, Kevin. The C# code I'm converting with JSIL doesn't do financial calculations (it's a mechanical engineering application), and mostly uses doubles. But for "historical" reasons some things are decimal types. I could probably convert the C# code to use doubles everywhere, but I'm trying to minimize the number of changes I make to the C# code.

This brings me to another question: The following works in jsil.org/try, but not in the code that I build using JSIL on my machine:

using System; using JSIL; using JSIL.Meta;

public static class Program {

public static void Main () { double dbl = 123.45; decimal dec;

dec = (decimal)dbl;

Console.WriteLine(dec);

} }

The cast works fine on jsil.org/try, but I get this error on my machine:

Unhandled exception: Error: The external method 'System.Decimal op_Explicit(System.Double)' of type 'System.Decimal' has not been implemented. Error: The external method 'System.Decimal op_Explicit(System.Double)' of type 'System.Decimal' has not been implemented. at Function.ExternalMemberStub (file:///C:/Users/Joy/Documents/GitHub/JSIL/Libraries/JSIL.Core.js:904:23) at Function.PreInitMethod_Invoke as op_Explicit$72=71 at JSIL.MethodSignature.CallStatic (file:///C:/Users/Joy/Documents/GitHub/JSIL/Libraries/JSIL.Core.js:5352:19) at Object.DelimitedProductData__ctor as _ctor$7,7,7,7=void at Object.Typector (file:///C:/Users/Joy/Documents/GitHub/JSIL/Libraries/JSIL.Core.js:3965:38) at Object.Typector_Once (file:///C:/Users/Joy/Documents/GitHub/JSIL/Libraries/JSIL.Core.js:3987:29) at Object.Qualtira_ProductSelectionPro_JsilTest_DelimitedProductData (jsil://closure/Qualtira.ProductSelectionPro.JsilTest.DelimitedProductData:5:29) at Object.Program_Main (file:///C:/Users/Joy/Documents/GitHub/JSIL/bin/JsilTest,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null.js:438:25) at Object.PreInitMethod_Invoke as Main$25[7]=void at runMain (file:///C:/Users/Joy/Documents/GitHub/JSIL/bin/default.html:32:52)

Sorry for what is probably a dumb question, but I just started working with JSIL today, and probably haven't figured much of it out yet.