Ticket #374 (new defect)
shared classes do not compile
Reported by: | ptokremin | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | Cobra Compiler | Version: | 0.9.6 |
Keywords: | Cc: |
Description
It is not possible to declare shared (static) classes.
The following definition...
namespace CobraDebug03 class LibTools is public, shared def doIt as String is public, shared return "great, it work's! :-)"
... produces error messages from the c# compiler (since they are in german on my system I translated them):
# cobra.bat -version Cobra svn:3116 (post 0.9.6) / 2014-07-10 on .NET CLR v4.0.30319 on Microsoft Windows NT 6.1.7601 Service Pack 1 #cobra.bat -c CobraDebug03.cobra d:\tmp\nh\CobraDebug03.cobra(5): error: "CobraDebug03.LibTools._ih_invariantGuard": instance members may not be declared in a static class d:\tmp\nh\CobraDebug03.cobra(5): error: static classes may not have an instance constructor Compilation failed - 2 errors, 0 warnings
The messages refer to the property _ih_invariantGuard and the constructor for the c#-class. Here's the intermediate code (without the #line tags) generated by cobra:
using CobraCoreInternal = Cobra.Core; namespace CobraDebug03 { public static class LibTools : global::System.Object { int _ih_invariantGuard; [CobraCoreInternal.NotNull] public static global::System.String DoIt() { return "greaaaat :-)"; } public LibTools() : base() { } } // class LibTools } // namespace CobraDebug03
A rather ugly work-around is NOT to declare the class as shared.
Change History
Note: See
TracTickets for help on using
tickets.