Ticket #347 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

Cannot make use of optional arguments declared in a library

Reported by: Charles Owned by: Charles
Priority: major Milestone:
Component: Cobra Compiler Version: 0.9.4
Keywords: Cc:


The optional argument support in Cobra doesn't work across libraries. In other words, if the method is declared like so:

class X

    def foo(verbose = false) as int
        return if(verbose, 1, 0)   

Then trying to invoke the method without an argument will work in the same code base, but fail in another project with:

error: The method "foo" is expecting 1 argument, but no arguments are being supplied in this call. The declaration is "foo(verbose as bool)"

This all came up because I tried using optional args in Cobra.Core after which some test cases failed the above error.

The solution will almost certainly be the generation and scanning of attributes on the argument. Ideally, we would use the same conventions as the C# compiler for maximum compatibility between Cobra and C#.

Change History

Changed 5 years ago by Charles

Not that we're trying to get things working on .NET < 4, but when I went looking too see what if any attributes the C# compile uses, I came across this:

Changed 5 years ago by Charles

  • owner set to hopscc
  • status changed from new to assigned

Changed 5 years ago by Charles

It turns out that .NET has had this feature for a long time and longer than C#. Reflection already covers this:



use System.Reflection

class X

    def one(a as int, b as int)
    def two(a as int, b as int = 5)

    def main is shared
        t = X
        for mi in t.getMethods(BindingFlags(Public, Instance, DeclaredOnly))
            trace mi
            for pi in mi.getParameters
                trace pi, pi.hasDefaultValue, pi.isOptional
                if pi.hasDefaultValue, trace pi.defaultValue

Changed 5 years ago by Charles

  • owner changed from hopscc to Charles

I got this.

Changed 5 years ago by Charles

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in changeset:3063

Changed 5 years ago by nerdzero

  • status changed from closed to reopened
  • resolution fixed deleted

Careful, I think .hasDefaultValue is from 4.5

Changed 5 years ago by Charles

Wow, thanks for the catch!

Changed 5 years ago by Charles

  • status changed from reopened to closed
  • resolution set to fixed

Dependency removed. My external test still works. Ran whole test suite.


Note: See TracTickets for help on using tickets.