You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2019/11/20 22:04:00 UTC
[jira] [Comment Edited] (GROOVY-9224) Compiler can't convert int to
String for @NamedParams[]
[ https://issues.apache.org/jira/browse/GROOVY-9224?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16978777#comment-16978777 ]
Eric Milles edited comment on GROOVY-9224 at 11/20/19 10:03 PM:
----------------------------------------------------------------
Static type checking produces an error on number argument for positional String parameter.
{code:groovy}
void meth(String string) {}
@CompileStatic
void test() {
meth(1) // [Static type checking] - Cannot find matching method script#meth(int). Please check if the declared type is correct and if the method exists.
}
{code}
was (Author: emilles):
Static type checking produces an error on number argument for String parameter.
{code:groovy}
void meth(String string) {}
@CompileStatic
void test() {
meth(1) // [Static type checking] - Cannot find matching method script#meth(int). Please check if the declared type is correct and if the method exists.
}
{code}
> Compiler can't convert int to String for @NamedParams[]
> -------------------------------------------------------
>
> Key: GROOVY-9224
> URL: https://issues.apache.org/jira/browse/GROOVY-9224
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.5.6
> Reporter: Ekaterina Alekseeva
> Priority: Major
>
> Try to compile following code with groovy-2.5.6:
> {code:java}
> @CompileStatic
> void namedParams(@NamedParams([
> @NamedParam(value = 'last', type = String)
> ]) Map args, int i) {
> print args.last
> }
> @CompileStatic
> def m() {
> namedParams(1, last: 1)// 1 (int) should be converted to String
> }
> {code}
>
> There will be an error: {color:#e01e5a}Error:(16, 17) Groovyc: [Static type checking] - parameter for named arg 'last' has type 'int' but expected 'java.lang.String'{color}
>
> It works fine in groovy 2.5.4 or if there's only one @NamedParam, like in this example:
> @CompileStatic
> void namedParam(@NamedParam(value = 'last', type = String) Map args, int i) {
> print args.last
> }
> @CompileStatic
> def m() {
> namedParam(1, last: 1) // 1 (int) successfully converted to String
> }
--
This message was sent by Atlassian Jira
(v8.3.4#803005)