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

    https://github.com/apache/groovy/pull/708#discussion_r188869080
  
    --- Diff: 
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java 
---
    @@ -4101,13 +4101,17 @@ protected static ClassNode 
getGroupOperationResultType(ClassNode a, ClassNode b)
             return Number_TYPE;
         }
     
    -    protected ClassNode inferComponentType(final ClassNode containerType, 
final ClassNode indexType) {
    +    private static ClassNode convertGStringToStringType(ClassNode cn) {
    +        return GSTRING_TYPE.equals(cn) ? STRING_TYPE : cn;
    +    }
    +
    +    protected ClassNode inferComponentType(final ClassNode containerType, 
ClassNode indexType) {
             final ClassNode componentType = containerType.getComponentType();
             if (componentType == null) {
                 // GROOVY-5521
                 // try to identify a getAt method
                 typeCheckingContext.pushErrorCollector();
    -            MethodCallExpression vcall = callX(varX("_hash_", 
containerType), "getAt", varX("_index_", indexType));
    +            MethodCallExpression vcall = callX(varX("_hash_", 
containerType), "getAt", varX("_index_", 
convertGStringToStringType(indexType)));
    --- End diff --
    
    we can treat GString as a String if we know the target is a String. Plus 
the rules for assignment and for method calls are not identical. But my comment 
was not about adding getAt(GString) for Map. My comment was that this change 
looks like the following will no longer work:
      
          class X {
            int getAt(GString gs) {1}
          }
          assert new X()["${42}"] == 1


---

Reply via email to