[jira] [Commented] (GROOVY-6668) Static compiler doesn't coerce GString for getAt() call

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (GROOVY-6668) Static compiler doesn't coerce GString for getAt() call

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/GROOVY-6668?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16478380#comment-16478380 ]

ASF GitHub Bot commented on GROOVY-6668:
----------------------------------------

Github user blackdrag commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/708#discussion_r188821671
 
    --- Diff: src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java ---
    @@ -468,7 +469,11 @@ protected void loadArguments(List<Expression> argumentList, Parameter[] para) {
                     expression.putNodeMetaData(PARAMETER_TYPE, para[i].getType());
                     expression.visit(acg);
                     if (!isNullConstant(expression)) {
    -                    operandStack.doGroovyCast(para[i].getType());
    +                    if (expression instanceof GStringExpression) {
    +                        operandStack.doGroovyCast(ClassHelper.STRING_TYPE);
    --- End diff --
   
    what if the method has a GString parameter? Converting to string is then wrong. You should add a test for this


> Static compiler doesn't coerce GString for getAt() call
> -------------------------------------------------------
>
>                 Key: GROOVY-6668
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6668
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.3.0-beta-1, 2.4.0-rc-1
>            Reporter: Luke Daley
>            Priority: Major
>
> This might not be a bug, but it's a behaviour change from 2.2.
> {code}
> @groovy.transform.CompileStatic
> class OtherThing {
>     OtherThing() {
>         Map<String, String> m = [:]
>         def k = "foo"
>         m["$k"].toUpperCase() // fails, no method toUpperCase() on object
>         m[k].toUpperCase() // works
>     }
> }
> {code}



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