Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9529

Static type checking сannot choose between Map#getAt(Object) and Object#getAt(String) methods

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.3
    • Fix Version/s: 4.0.0-alpha-1, 3.0.4
    • Component/s: Static compilation
    • Labels:
      None
    • Environment:
      Groovy Version: 3.0.3 JVM: 11.0.7 Vendor: Azul Systems, Inc. OS: Linux

      Description

      Script:

      import groovy.transform.CompileStatic
      
      interface SimpleFeatureMap extends Map<Object, Object> {}
      interface FeatureMap extends SimpleFeatureMap{}
      class FeatureMapImpl extends HashMap<Object, Object> implements FeatureMap {}
      
      @CompileStatic
      class Test {
          FeatureMap newMap() {
              new FeatureMapImpl()
          }
          String test() {
              FeatureMap map = newMap()
              map['asd']
          }
      }
      
      new Test().test()
      

      Result:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      ideaGroovyConsole.groovy: 14: [Static type checking] - Reference to method is ambiguous. Cannot choose between [V java.util.Map <K, V>#getAt(java.lang.Object), java.lang.Object java.lang.Object#getAt(java.lang.String)]
       @ line 14, column 9.
                 map['asd']
                 ^
      
      1 error
      
      	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:287)
      	at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:963)
      	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:650)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:627)
      	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:389)
      	at groovy.lang.GroovyClassLoader.lambda$parseClass$3(GroovyClassLoader.java:332)
      	at org.codehaus.groovy.runtime.memoize.StampedCommonCache.compute(StampedCommonCache.java:163)
      	at org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:154)
      	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:330)
      	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:526)
      	at groovy.lang.GroovyShell.run(GroovyShell.java:359)
      	at groovy.lang.GroovyShell.run(GroovyShell.java:339)
      

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              Eliak Aleksey
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h