Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.5.9
-
None
Description
Consider this example:
package test58 import groovy.transform.CompileStatic; @CompileStatic public class Test58 { Map<String, String> m = [ foo: 'foo' ] void blah() { Object c = boh() def a = m.get(c) uhuh(a) def b = m[c] uhuh(b) } void uhuh(String a) { } Object boh() { 'foo' } }
The call uhuh(b) fails with error:
Groovy:[Static type checking] - Cannot find matching method test58.Test58#uhuh(java.lang.Object). Please check if the declared type is correct and if the method exists.
However, since m is a Map<String, String>, b type should be inferred as String.
If an error is in this code, I think it should be signalled on the def b = m[c] assignment (or even def a = m.get(c)), because c declared type is Object, and not on the subsequent call involving b.
Perhaps here c is inferred as String thanks to flow typing, but then I still believe uhuh(b) should succeed, just like uhuh(a) does.
Originally submitted for Groovy Eclipse Plugin at: https://github.com/groovy/groovy-eclipse/issues/948
Attachments
Issue Links
- relates to
-
GROOVY-8788 Inconsistency in extension method selection with @CompileStatic
- Closed
- links to