sq / JSIL

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

Class with T[] generic array field does not compile #1016

Open wizzard0 opened 8 years ago

wizzard0 commented 8 years ago

JSIL version https://github.com/sq/JSIL/commit/b4f2ff8867a05158727bbd58e7c56b3fe0b009e7

    [Serializable]
    [JSProxy("System.ArraySegment`1")]
    public class ArraySegment<T> //: IList<T>, IReadOnlyList<T>
    {
        private T[] _arrayRef;
        public ArraySegment(T[] array, int offset, int count) { }
    }

-->

// Writing JS   System.Exception: Error occurred while generating javascript for assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. ---> System.Exception: An error occurred while declaring the type 'Syst
em.ArraySegment`1' ---> System.NotImplementedException: Unimplemented form of generic type parameter: 'T'.
   at JSIL.Internal.JavascriptFormatter.TypeReferenceInternal(GenericParameter gp, TypeReferenceContext context) in C:\dev\JSIL\JSIL\JavascriptFormatter.cs:line 578
   at JSIL.Internal.JavascriptFormatter.TypeReference(TypeReference type, TypeReferenceContext context) in C:\dev\JSIL\JSIL\JavascriptFormatter.cs:line 775
   at JSIL.Internal.JavascriptFormatter.TypeReferenceInternal(ArrayType at, TypeReferenceContext context) in C:\dev\JSIL\JSIL\JavascriptFormatter.cs:line 708
   at JSIL.Internal.JavascriptFormatter.TypeReference(TypeReference type, TypeReferenceContext context) in C:\dev\JSIL\JSIL\JavascriptFormatter.cs:line 777
   at JSIL.JavascriptAssemblyEmitter.EmitFieldOrConstant(DecompilerContext context, IAstEmitter astEmitter, FieldDefinition field, JSRawOutputIdentifier dollar, JSExpression defaultValue, Boolean isConstant) in C:\dev\JSIL\JSIL\JavascriptAs
semblyEmitter.cs:line 1207
   at JSIL.JavascriptAssemblyEmitter.EmitField(DecompilerContext context, IAstEmitter astEmitter, FieldDefinition field, JSRawOutputIdentifier dollar, JSExpression defaultValue) in C:\dev\JSIL\JSIL\JavascriptAssemblyEmitter.cs:line 1366
   at JSIL.AssemblyTranslator.<>c__DisplayClass107_0.<TranslateTypeStaticConstructor>b__10(FieldDefinition fd) in C:\dev\JSIL\JSIL\AssemblyTranslator.cs:line 1906
   at JSIL.AssemblyTranslator.TranslateTypeStaticConstructor(DecompilerContext context, TypeDefinition typedef, IAstEmitter astEmitter, IAssemblyEmitter assemblyEmitter, MethodDefinition cctor, Boolean stubbed, JSRawOutputIdentifier dollar,
 Cachers cachers) in C:\dev\JSIL\JSIL\AssemblyTranslator.cs:line 1931
   at JSIL.AssemblyTranslator.TranslateTypeDefinition(DecompilerContext context, TypeDefinition typedef, IAstEmitter astEmitter, IAssemblyEmitter assemblyEmitter, Boolean stubbed, JSRawOutputIdentifier dollar, Cachers cachers) in C:\dev\JSI
L\JSIL\AssemblyTranslator.cs:line 1298
   at JSIL.AssemblyTranslator.DeclareType(DecompilerContext context, TypeDefinition typedef, IAstEmitter astEmitter, IAssemblyEmitter assemblyEmitter, HashSet`1 declaredTypes, Boolean stubbed, Boolean isImported) in C:\dev\JSIL\JSIL\Assembl
yTranslator.cs:line 1126
   --- End of inner exception stack trace ---
   at JSIL.AssemblyTranslator.DeclareType(DecompilerContext context, TypeDefinition typedef, IAstEmitter astEmitter, IAssemblyEmitter assemblyEmitter, HashSet`1 declaredTypes, Boolean stubbed, Boolean isImported) in C:\dev\JSIL\JSIL\Assembl
yTranslator.cs:line 1142
   at JSIL.AssemblyTranslator.TranslateModule(DecompilerContext context, IAssemblyEmitter assemblyEmitter, ModuleDefinition module, HashSet`1 sealedTypes, HashSet`1 declaredTypes, Boolean stubbed) in C:\dev\JSIL\JSIL\AssemblyTranslator.cs:l
ine 1026
   at JSIL.AssemblyTranslator.TranslateSingleAssemblyInternal(IAssemblyEmitter assemblyEmitter, DecompilerContext context, AssemblyDefinition assembly, Stream outputStream, SourceMapBuilder sourceMapBuilder) in C:\dev\JSIL\JSIL\AssemblyTran
slator.cs:line 938
   at JSIL.AssemblyTranslator.<>c__DisplayClass79_0.<TranslateInternal>b__1(Int32 i) in C:\dev\JSIL\JSIL\AssemblyTranslator.cs:line 546
   --- End of inner exception stack trace ---
   at JSIL.AssemblyTranslator.<>c__DisplayClass79_0.<TranslateInternal>b__1(Int32 i) in C:\dev\JSIL\JSIL\AssemblyTranslator.cs:line 550
   at JSIL.AssemblyTranslator.TranslateInternal(String assemblyPath, Boolean scanForProxies) in C:\dev\JSIL\JSIL\AssemblyTranslator.cs:line 580
   at JSIL.AssemblyTranslator.Translate(String assemblyPath, Boolean scanForProxies) in C:\dev\JSIL\JSIL\AssemblyTranslator.cs:line 452
   at JSIL.Compiler.Profiles.BaseProfile.Translate(VariableSet variables, AssemblyTranslator translator, Configuration configuration, String assemblyPath, Boolean scanForProxies) in C:\dev\JSIL\Compiler\Profiles\Base.cs:line 19
   at JSIL.Compiler.Program.InternalMain(String[] arguments) in C:\dev\JSIL\Compiler\Program.cs:line 821
   at JSIL.Compiler.Program.Main(String[] arguments) in C:\dev\JSIL\Compiler\Program.cs:line 699
Press any key to continue . . .
iskiselev commented 8 years ago

I believe there are some problems with proxy for generic classes. There should not be any problem if you just mark it all class or methods with JSExternalAttribute and implement it yourself with javascript.

iskiselev commented 8 years ago

Could you provide full case to reproduce?