[ https://issues.apache.org/jira/browse/GROOVY-8190?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King updated GROOVY-8190: ------------------------------ Description: open groovy console, paste code below {code} import groovy.transform.* @CompileStatic void foo(Map<Map<String, String>, List<Map<String, Object>>> map){ for(Map<String, String> key : map.keySet()) { def x = map[key] def y = x[0][""] } } {code} and you will see it fails to compile {noformat} Result: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: ideaGroovyConsole.groovy: 7: [Static type checking] - Cannot find matching method java.lang.Object#getAt(int). Please check if the declared type is right and if the method exists. @ line 7, column 17. def y = x[0][""] ^ 1 error at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310) at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1075) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688) at groovy.lang.GroovyShell.run(GroovyShell.java:517) at groovy.lang.GroovyShell.run(GroovyShell.java:497) at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:169) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) at console.run(console.txt:25) at groovy.ui.GroovyMain.processReader(GroovyMain.java:631) at groovy.ui.GroovyMain.processFiles(GroovyMain.java:539) at groovy.ui.GroovyMain.run(GroovyMain.java:382) at groovy.ui.GroovyMain.process(GroovyMain.java:370) at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129) at groovy.ui.GroovyMain.main(GroovyMain.java:109) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109) at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:65) {noformat} and if you change map key to other type (e.g a {{List<>}}), it will compile just fine. was: open groovy console, paste code below {code} import groovy.transform.* @CompileStatic void foo(Map<Map<String, String>, List<Map<String, Object>>> map){ for(Map<String, String> key : map.keySet()) { def x = map[key] def y = x[0][""] } } {code} and you will see it fails to compile {code} > import groovy.transform.* @CompileStatic void foo(Map<Map<String, String>, List<Map<String, Object>>> map){ for(Map<String, String> key : map.keySet()) { def x = map[key] def y = x[0][""] } } Result: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: ideaGroovyConsole.groovy: 7: [Static type checking] - Cannot find matching method java.lang.Object#getAt(int). Please check if the declared type is right and if the method exists. @ line 7, column 17. def y = x[0][""] ^ 1 error at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310) at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1075) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688) at groovy.lang.GroovyShell.run(GroovyShell.java:517) at groovy.lang.GroovyShell.run(GroovyShell.java:497) at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:169) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) at console.run(console.txt:25) at groovy.ui.GroovyMain.processReader(GroovyMain.java:631) at groovy.ui.GroovyMain.processFiles(GroovyMain.java:539) at groovy.ui.GroovyMain.run(GroovyMain.java:382) at groovy.ui.GroovyMain.process(GroovyMain.java:370) at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129) at groovy.ui.GroovyMain.main(GroovyMain.java:109) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109) at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:65) {code} and if you change map key to other type (eg a List<>), it will compile just fine. > CompileStatic cant infer type when using map as map key > ------------------------------------------------------- > > Key: GROOVY-8190 > URL: https://issues.apache.org/jira/browse/GROOVY-8190 > Project: Groovy > Issue Type: Bug > Affects Versions: 2.4.6 > Reporter: Richard Zhang > > open groovy console, paste code below > {code} > import groovy.transform.* > @CompileStatic > void foo(Map<Map<String, String>, List<Map<String, Object>>> map){ > for(Map<String, String> key : map.keySet()) { > def x = map[key] > def y = x[0][""] > } > } > {code} > and you will see it fails to compile > {noformat} > Result: org.codehaus.groovy.control.MultipleCompilationErrorsException: > startup failed: > ideaGroovyConsole.groovy: 7: [Static type checking] - Cannot find matching > method java.lang.Object#getAt(int). Please check if the declared type is > right and if the method exists. > @ line 7, column 17. > def y = x[0][""] > ^ > 1 error > at > org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310) > at > org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1075) > at > org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591) > at > org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569) > at > org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546) > at > groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) > at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) > at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688) > at groovy.lang.GroovyShell.run(GroovyShell.java:517) > at groovy.lang.GroovyShell.run(GroovyShell.java:497) > at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:498) > at > org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:169) > at > org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) > at console.run(console.txt:25) > at groovy.ui.GroovyMain.processReader(GroovyMain.java:631) > at groovy.ui.GroovyMain.processFiles(GroovyMain.java:539) > at groovy.ui.GroovyMain.run(GroovyMain.java:382) > at groovy.ui.GroovyMain.process(GroovyMain.java:370) > at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129) > at groovy.ui.GroovyMain.main(GroovyMain.java:109) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:498) > at > org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109) > at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:498) > at > com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:65) > {noformat} > and if you change map key to other type (e.g a {{List<>}}), it will compile > just fine. -- This message was sent by Atlassian JIRA (v6.3.15#6346)