Page 1 of 1

"internal error" with assembly has Attribute

PostPosted: Sat Jan 03, 2009 8:37 pm
by gauthier
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.

Re: "internal error" with assembly has Attribute

PostPosted: Sat Jan 03, 2009 10:56 pm
by Charles
Fixed, tested and checked in. Thanks for the report.

Re: "internal error" with assembly has Attribute

PostPosted: Sun Jan 04, 2009 5:58 am
by gauthier
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

Re: "internal error" with assembly has Attribute

PostPosted: Sun Jan 04, 2009 6:25 am
by gauthier
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.

Re: "internal error" with assembly has Attribute

PostPosted: Sun Jan 04, 2009 11:36 am
by Charles
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

Re: "internal error" with assembly has Attribute

PostPosted: Sun Jan 04, 2009 11:39 am
by Charles
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.

Re: "internal error" with assembly has Attribute

PostPosted: Mon Jan 05, 2009 8:36 pm
by Charles
I fixed ticket:121 so you can now use qualified attributes.

Let me know if you have any outstanding problems.

Re: "internal error" with assembly has Attribute

PostPosted: Fri Jan 09, 2009 4:04 am
by Charles
This required a further fix for some additional cases. Now done and checked in with test case.