Page 1 of 1

Internal Error with Named Arguments

PostPosted: Mon Apr 21, 2014 5:34 pm
by oahmad04
I'm pretty sure this one's not my fault...

If I have the following file:
@args target:lib

namespace Bad

class Thing

cue init(name)
base.init
print name

class Other inherits Thing

cue init
base.init(name = 'fries')


I get the following error:
Code: Select all
error: COBRA INTERNAL ERROR / NullReferenceException / Object reference not set to an instance of an object


Cobra svn: 3116
Mac OS X 10.9.2

Thanks

Re: Internal Error with Named Arguments

PostPosted: Tue Apr 22, 2014 2:14 am
by hopscc
Youre not setting default args here and I dont believe cobra has named arg assignment

This is attempting to call a noarg ctor and set a property called (.name) neither of which exist (assignment in call not in declaration)
( the error message could be better)

This instead for default named args:

@args target:lib

namespace NotSoBad

class Thing

cue init(name)
base.init
print name

class Other inherits Thing

cue init(name = 'fries')
base.init(name)

Re: Internal Error with Named Arguments

PostPosted: Tue Apr 22, 2014 4:26 am
by hopscc
and I dont believe cobra has named arg assignment


oops it does :oops:
so what you wrote should work....
The assignment expression is missing a couple of the binding phases for some reason...

Re: Internal Error with Named Arguments

PostPosted: Wed Apr 23, 2014 1:29 am
by hopscc
Well I've found the cause of this - seems the tree code change supporting all this ( keyword and default args) had a line from the patch commented out
(Expr.cobra line 827).

reasserting that gives a compile pass but emits a C# compilation error as does trying to do the above purely in C# so looks like this particular combo of named args on initialisers (pass through to ancestors) isnt supported in C# either...

Code: Select all
namespace Bad {
        public class Thing : System.Object {

                public  Thing( object name) : base() {
                        System.Console.WriteLine(name);
                }

        } // class Thing

        public class Other : Bad.Thing {

                public  Other() : base(name="fries") {
                        System.String name = null;
                }

        } // class Other

} // namespace Bad

gives
Code: Select all
620 xx:...src/cobra/Tst/2014> cobra defArgErr.cs
c:\Users\hops\src\cobra\Tst\2014\defArgErr.cs(12): error: The name "name" does not exist in the current context (C#)
Compilation failed - 1 error, 0 warnings
Not running due to errors above.