kjm00king / sharpkit

Automatically exported from code.google.com/p/sharpkit
0 stars 0 forks source link

Field initialisation with lambda errors in compilation #298

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Using a lambda in an object creation in a field errors in the SharpKit compiler.

    [JsType(JsMode.Clr, Filename = "res/InitialiseTest.js")]
    public class Circle<T>
    {
        public Circle(Func<T, T, int> func)
        {
            new jQuery(HtmlContext.document.body).append("Circle created<br/>");
        }
    }

    [JsType(JsMode.Clr, Filename = "res/InitialiseTest.js")]
    public class Boxes
    {
        Circle<int> circle = new Circle<int>((a, b) => a + b);

        public Boxes()
        {
        }
    }

    [JsType(JsMode.Global, Filename = "res/Default.js")]
    public class DefaultClient
    {
        static void DefaultClient_Load()
        {
            new jQuery(HtmlContext.document.body).append("Ready<br/>");
        }
        static void btnTest_click(DOMEvent e)
        {
            Boxes boxes = new Boxes();

            new jQuery(HtmlContext.document.body).append("Hello world<br/>");
        }
    }

The error produced is:

Error   7   Unable to cast object of type 
'ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultResolvedField' to type 
'ICSharpCode.NRefactory.TypeSystem.IMethod'. [c:\users\_______\documents\visual 
studio 
2012\Projects\SharpKitWebApp3\SharpKitWebApp3\DefaultClient.cs] c:\users\_______
\documents\visual studio 
2012\Projects\SharpKitWebApp3\SharpKitWebApp3\DefaultClient.cs  20  46  SharpKitWeb
App3

I think this may be a regression, previous versions didn't experience a compile 
error on existing code. It might be related to 

Issue 296: Complex field initializers fail

The full log is:

1>------ Build started: Project: SharpKitWebApp3, Configuration: Debug Any CPU 
------
1>  Parallel=False
1>  C:\Windows\Microsoft.NET\Framework\v4.0.30319\SharpKit\5\skc5.exe 
/dir:"c:\users\________\documents\visual studio 
2012\Projects\SharpKitWebApp3\SharpKitWebApp3" /define:TRACE;DEBUG 
/reference:"C:\Program Files (x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\Microsoft.CSharp.dll" 
/reference:"C:\Program Files (x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" 
/reference:"C:\Program Files 
(x86)\SharpKit\5\Assemblies\v4.0\SharpKit.Html.dll" /reference:"C:\Program 
Files (x86)\SharpKit\5\Assemblies\v4.0\SharpKit.JavaScript.dll" 
/reference:"C:\Program Files 
(x86)\SharpKit\5\Assemblies\v4.0\SharpKit.jQuery.dll" /reference:"C:\Program 
Files (x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Configuration.dll" 
/reference:"C:\Program Files (x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll" 
/reference:"C:\Program Files (x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll" 
/reference:"C:\Program Files (x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll" 
/reference:"C:\Program Files (x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Drawing.dll" 
/reference:"C:\Program Files (x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.EnterpriseServices.dll"
 /reference:"C:\Program Files (x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.ApplicationServices
.dll" /reference:"C:\Program Files (x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.dll" 
/reference:"C:\Program Files (x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.Extensions.dll" 
/reference:"C:\Program Files (x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.Services.dll" 
/reference:"C:\Program Files (x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.dll" 
/reference:"C:\Program Files (x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.Linq.dll" 
/out:obj\Debug\SharpKitWebApp3.dll /target:library Default.aspx.cs 
Default.aspx.designer.cs Properties\AssemblyInfo.cs DefaultClient.cs 
"C:\Users\________\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttribu
tes.cs" /contentfile:Default.aspx /contentfile:res\Default.js 
/contentfile:res\InitialiseTest.js /contentfile:res\jquery-1.8.2.min.js 
/contentfile:res\jsclr.js /contentfile:Web.config /nonefile:Web.Debug.config 
/nonefile:Web.Release.config /TargetFrameworkVersion:v4.0
1>  13:35:21.492: ParseArgs: Start: 
1>  13:35:21.494: ParseArgs: End: 1ms
1>  13:35:21.494: CalculateMissingArgs: Start: 
1>  13:35:21.495: CalculateMissingArgs: End: 0ms
1>  13:35:21.495: CheckManifest: Start: 
1>  Reasons for rebuild:
1>  Added source files:
1>  "DefaultClient.cs", Modified:-8588288383901758584, Size:
1>  Removed source files:
1>  "DefaultClient.cs", Modified:-8588288384494315771, Size:
1>  
1>  13:35:21.500: CheckManifest: End: 5ms
1>  13:35:21.500: VerifyNativeImage: Start: 
1>  13:35:21.500: VerifyNativeImage: End: 0ms
1>  13:35:21.500: CheckActivation: Start: 
1>  SharpKit 5 Professional Edition v5.01.7000
1>  13:35:21.504: CheckActivation: End: 4ms
1>  13:35:21.504: LoadPlugins: Start: 
1>  13:35:21.505: LoadPlugins: End: 0ms
1>  13:35:21.505: ParseCs: Start: 
1>  13:35:21.518: 5 Source files
1>  13:35:21.528: Sources files End: 10
1>  13:35:21.528: 17 References
1>  13:35:22.482: 17 References End:
1>  13:35:22.483: CreateCompilation
1>  13:35:22.484: ParseCs: End: 979ms
1>  13:35:22.484: ApplyExternalMetadata: Start: 
1>  13:35:22.495: ApplyExternalMetadata: End: 10ms
1>  13:35:22.495: ConvertCsToJs: Start: 
1>  13:35:22.500: ApplyNavigator
1>  13:35:22.509: ApplyNavigator End:8
1>c:\users\________\documents\visual studio 
2012\Projects\SharpKitWebApp3\SharpKitWebApp3\DefaultClient.cs(20,46): error 
SK0000: Unable to cast object of type 
'ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultResolvedField' to type 
'ICSharpCode.NRefactory.TypeSystem.IMethod'. 
[c:\users\________\documents\visual studio 
2012\Projects\SharpKitWebApp3\SharpKitWebApp3\DefaultClient.cs]
1>  SharpKit.Compiler.CompilerException: Unable to cast object of type 
'ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultResolvedField' to type 
'ICSharpCode.NRefactory.TypeSystem.IMethod'. ---> System.InvalidCastException: 
Unable to cast object of type 
'ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultResolvedField' to type 
'ICSharpCode.NRefactory.TypeSystem.IMethod'.
1>     at SharpKit.Compiler.Extensions.GetParentMethod(ResolveResult res)
1>     at 
SharpKit.Compiler.JsCodeImporter.VisitLambdaResolveResult(LambdaResolveResult 
res)
1>     at 
ICSharpCode.NRefactory.CSharp.Resolver.LambdaResolveResult.AcceptVisitor[R](IRes
olveResultVisitor`1 visitor)
1>     at SharpKit.Compiler.JsCodeImporter.Visit(ResolveResult res)
1>     --- End of inner exception stack trace ---
1>     at SharpKit.Compiler.JsTypeImporter.Visit(IEntity node)
1>     at SharpKit.Compiler.JsModelImporter.ExportType(ITypeDefinition ce)
1>     at SharpKit.Compiler.JsModelImporter.ExportType(ITypeDefinition ce, 
JsFile jsFile)
1>     at 
SharpKit.Compiler.JsModelImporter.<>c__DisplayClass13.<ExportTypesInFile>b__12(I
TypeDefinition t)
1>     at System.Collections.Generic.List`1.ForEach(Action`1 action)
1>     at SharpKit.Compiler.JsModelImporter.ExportTypesInFile(KeyValuePair`2 p)
1>     at System.Linq.Extensions.ForEach[T](IEnumerable`1 items, Action`1 
action)
1>     at 
System.Collections.Generic.CollectionExtensions.ForEachParallel[T](IEnumerable`1
 items, Action`1 action, Boolean parallel)
1>     at SharpKit.Compiler.JsModelImporter.Process()
1>     at SharpKit.Compiler.CompilerTool.ConvertCsToJs()
1>     at SharpKit.Compiler.CompilerTool.Time(Action action)
1>     at SharpKit.Compiler.CompilerTool.InternalRun()
1>  Total: 1038ms
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

Original issue reported on code.google.com by co...@gravill.com on 2 Jul 2013 at 12:44

GoogleCodeExporter commented 8 years ago

Original comment by DanelK...@gmail.com on 3 Jul 2013 at 7:44