Cannot build using .NET 4.0, problem in JsMathConstructor.cs

Dec 16, 2011 at 5:07 PM

There seems to be a compatibility error in .NET 4.0, which is somewhat non-obvious..

I am trying to build the tip (a1e6deb9fc0c)

I have reset the projects to use .NET 4.0, and in I removed the duplicate definitions of Func and friends from JintEngine since they are defined similarly in System.

Now I get  bunch of compile errors, all similar, inside JsMathConstructor.cs, for example...

Error 15 The type 'double' cannot be used as type parameter 'T' in the generic type or method 'Jint.Native.JsFunctionConstructor.New<T>(System.Func<T,Jint.Native.JsInstance>)'. There is no boxing conversion from 'double' to 'Jint.Native.JsInstance'. c:\root\logical\Prebuilt\Jint\20111216\Jint\Native\JsMathConstructor.cs 15 27 Jint

Which refers to:

this["abs"] = global.FunctionClass.New(new Func<doubleJsNumber>(d => Global.NumberClass.New(Math.Abs(d))));

To my mind this is a genuine error, since the matching New function is generic, but defined with a constraint that T be a JInstance:

public JsFunction New<T>(Func<T, JsInstance> impl) where T : JsInstance { ... }

It is OK if I cast to a Delegate as this matches a different "New", but I am unsure if that is technically correct... Interestingly if I compile with .NET 3.5, the matching rules are different!, so in that universe New(Delegate) is matched by default.

I plan to change all the problem lines by adding an explicit cast to Delegate..., that would (I think) be backwards compatible.

this["abs"] = global.FunctionClass.New((Delegate)new Func<doubleJsNumber>(d => Global.NumberClass.New(Math.Abs(d))));

Does that seem OK?