boo-lang / boo

The Boo Programming Language.
BSD 3-Clause "New" or "Revised" License
874 stars 148 forks source link

[required] does not work on closures #131

Closed BitPuffin closed 8 years ago

BitPuffin commented 8 years ago
def A():
    def c([required] s as string):
        pass
booc requiredclosure.boo
Boo Compiler version 0.9.7.0 (CLR 2.0.50727.8009)
requiredclosure.boo(2,5): BCW0003: WARNING: Unused local variable 'c'.
1 warning(s).
requiredclosure.boo(2,12): BCE0015: Node '[required]' has not been correctly processed.
1 error(s).
masonwheeler commented 8 years ago

This appears to be caused by BindAndApplyAttributes.OnBlock():

    override public void OnBlock(Block node)
    {
        // No need to visit blocks
    }

This prevents the visitor from recursing into the body of A, visiting the BlockExpression inside of it, and applying the attribute on its arguments. So apparently there is a need after all. :)

masonwheeler commented 8 years ago

After removing that, this specific case still fails due to the following code in RequiredAttribute:

private def TargetMethod(parameter as ParameterDeclaration):
    method = parameter.ParentNode as Method
    return method if method is not null

    property = parameter.ParentNode as Property
    CheckProperty property
    return property.Setter

private def CheckProperty(property as Property):
    if property is null or property.Setter is null:
        InvalidNodeForAttribute('ParameterDeclaration or Property')

This attribute expects to be placed on a ParameterDeclaration for a Method, or on a Property for which it can extract a Setter Method. It doesn't know how to deal with a ParameterDeclaration on a BlockExpression.

What it actually needs, though, is not a Method, but the Block that represents the method's body. Fixing this too.

masonwheeler commented 8 years ago

Found that the same problem exists on DefaultAttribute. Fixing it there as well.

BitPuffin commented 8 years ago

Awesome, nice work. I was considering looking into it myself as it seemed like a pretty approachable bug. But thanks for saving me the trouble! :)