Forums

"internal error" with assembly has Attribute

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

"internal error" with assembly has Attribute

Postby gauthier » Sat Jan 03, 2009 8:37 pm

assembly
has Define()

namespace here
class DefineAttribute
inherits Attribute


class Program
def main is shared
print 1


gives

Code: Select all
error: COBRA INTERNAL ERROR / RequireException / ; sourceSite = C:\home\dev\src\dotnet\projects\cobralanguage\Source\Compiler.cobra:190 in Compiler.curBox.get for object Compiler(5); info       = nil; this       = Compiler(5);     .boxStack.count = 0;         .boxStack = Stack<of Box>[];
Compilation failed - 1 error, 0 warnings
Not running due to errors above.
gauthier
 
Posts: 116

Re: "internal error" with assembly has Attribute

Postby Charles » Sat Jan 03, 2009 10:56 pm

Fixed, tested and checked in. Thanks for the report.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: "internal error" with assembly has Attribute

Postby gauthier » Sun Jan 04, 2009 5:58 am

By the way, I also get NullReferenceException with my nearby code.

Here is the detailed stack trace, I'm looking for a short reproductible case:
Code: Select all
    [cobra] Binding use directives
    [cobra] Binding inheritance
    [cobra] Binding interface
    [cobra] Binding implementation
    [cobra]
    [cobra] Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
    [cobra]    at TypeExpr.WriteSharpDef(SharpWriter sw, Boolean parens) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\Expr.cobra:line 3587
    [cobra]    at DotExpr._writeSharpDef(SharpWriter sw) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\BinaryOpExpr.cobra:line 4408
    [cobra]    at BinaryOpExpr.WriteSharpDef(SharpWriter sw, Boolean parens) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\BinaryOpExpr.cobra:line 3961
    [cobra]    at Expr.WriteSharpDef(SharpWriter sw) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\Expr.cobra:line 2996
    [cobra]    at Expr.WriteSharpDefInContext(SharpWriter sw, Boolean parens) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\Expr.cobra:line 2985
    [cobra]    at Expr.WriteSharpDefInContext(SharpWriter sw) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\Expr.cobra:line 2967
    [cobra]    at AttributeDecl.WriteSharpDef(SharpWriter sw, String prefix) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\Attributes.cobra:line 4574
    [cobra]    at AssemblyDecl.WriteSharpDef(SharpWriter sw) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\Attributes.cobra:line 4586
    [cobra]    at NameSpace.WriteSharpDef(SharpWriter sw) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\NameSpace.cobra:line 609
    [cobra]    at CobraModule.WriteSharpDef() in c:\home\dev\src\dotnet\projects\cobralanguage\Source\Module.cobra:line 464
    [cobra]    at Compiler.WriteSharp() in c:\home\dev\src\dotnet\projects\cobralanguage\Source\Compiler.cobra:line 46
    [cobra]    at ClrBackEnd.GenerateCode(Boolean writeTestInvocation) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\BackEndClr\backendclr\SharpGenerator.cobra:line 21
    [cobra]    at Compiler._compileFilesNamed(IList`1 paths, Boolean writeTestInvocation, Boolean stopAfterBindInt) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\Compiler.cobra:line 309
    [cobra]    at Compiler.CompileFilesNamed(IList`1 paths, Boolean writeTestInvocation, Boolean stopAfterBindInt) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\Compiler.cobra:line 264
    [cobra]    at CommandLine.DoCompile(List`1 paths, Boolean willPrintSuccessMsg, Boolean writeTestInvocation, Boolean stopAfterBindInt) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\CommandLine.cobra:line 570
    [cobra]    at CommandLine.DoCompile(List`1 paths) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\CommandLine.cobra:line 548
    [cobra]    at CommandLine.Run(List`1 args) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\CommandLine.cobra:line 529
    [cobra]    at CommandLine.Run() in c:\home\dev\src\dotnet\projects\cobralanguage\Source\CommandLine.cobra:line 485
    [cobra]    at CobraMain.Main() in c:\home\dev\src\dotnet\projects\cobralanguage\Source\cobra.cobra:line 13
gauthier
 
Posts: 116

Re: "internal error" with assembly has Attribute

Postby gauthier » Sun Jan 04, 2009 6:25 am

Do you know why this code
assembly
has here.MyAttribute(here.MyAttribute.constValue)

namespace here
class MyAttribute
has AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)
inherits Attribute
shared
get constValue as String
return "azerty"

def init(value as String)
.value = value
pro value from var as String

class Program
def main is shared

give
Code: Select all
main.cobra(2): error: main.cobra(2,50): error: Invalid attribute.
Compilation failed - 1 error, 0 warnings
Not running due to errors above.
gauthier
 
Posts: 116

Re: "internal error" with assembly has Attribute

Postby Charles » Sun Jan 04, 2009 11:36 am

Because the Cobra parser is not accepting qualified attribute names. Also, I coded up the C# equivalent and the use of a property would have also failed:
Code: Select all
using System;

[assembly: Here.MyAttribute(Here.MyAttribute.ConstValue)]

namespace Here {

   [AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)]
   public class MyAttribute : Attribute {

      // cannot use property values in attribute constructors
      //static public String ConstValue {
      //    get { return "azerty"; }
      //}

      // cannot use readonly fields in attribute constructors
      // static public readonly String ConstValue = "azerty";

      // C# error: An attribute argument must be a constant expression, typeof expression or array creation expression
      
      public const String ConstValue = "azerty";
      
      public MyAttribute(String value) {
         Value = value;
      }
      
      String _value;
      
      public String Value {
         get { return _value; }
         set { _value = value; }
      }

   }      

   public class Program {
      
      static public void Main() {
      }
      
   }
   
}

I have added two tickets:

-- ticket:121
-- ticket:122
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: "internal error" with assembly has Attribute

Postby Charles » Sun Jan 04, 2009 11:39 am

gauthier wrote:By the way, I also get NullReferenceException with my nearby code.

Here is the detailed stack trace, I'm looking for a short reproductible case:
Code: Select all
    [cobra] Binding use directives
    [cobra] Binding inheritance
    [cobra] Binding interface
    [cobra] Binding implementation
    [cobra]
    [cobra] Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
    [cobra]    at TypeExpr.WriteSharpDef(SharpWriter sw, Boolean parens) in c:\home\dev\src\dotnet\projects\cobralanguage\Source\Expr.cobra:line 3587
...

If that's the same line 3587 that I have in SharpGenerator.cobra (extensions report the wrong line number in stack traces):
if .curBox.name + '.' in sharpRef

then .curBox is returning nil and this is probably related to assembly level attributes.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: "internal error" with assembly has Attribute

Postby Charles » Mon Jan 05, 2009 8:36 pm

I fixed ticket:121 so you can now use qualified attributes.

Let me know if you have any outstanding problems.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: "internal error" with assembly has Attribute

Postby Charles » Fri Jan 09, 2009 4:04 am

This required a further fix for some additional cases. Now done and checked in with test case.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 75 guests