Vladimír Oraný created GROOVY-8889:
--------------------------------------

             Summary: @NamedParam(required=true) is not enforced
                 Key: GROOVY-8889
                 URL: https://issues.apache.org/jira/browse/GROOVY-8889
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 2.5.4
            Reporter: Vladimír Oraný


in following snipped the required parameter is not enforced at all:


{code}
import groovy.transform.CompileStatic
import groovy.transform.NamedParam
import groovy.transform.NamedParams

@CompileStatic
class Tester {
    String text
    String color

    static Tester note(String text, String color) {
        return new Tester(text: text, color: color)
    }
}

@CompileStatic
class TesterBuilder {
    static Tester note(
            @NamedParams([
                    @NamedParam(value = 'text', type = String, required = true),
                    @NamedParam(value = 'color', type = String)
            ])
            Map<String, String> params
    ) {
        return Tester.note(params.text, params.color)
    }
}


@CompileStatic
Tester useBuilder() {
    return TesterBuilder.note(color: 'blue')
}

useBuilder()
{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to