I wanted to discuss the strictness of Groovy's static type checking before
Groovy 3 is released and change becomes difficult. Recent changes have
replaced some instances of type coercion with STC errors. It was suggested in
one of the bug tickets to discuss before accepting the new strictness or making
some adjustments to allow some number type conversions and possibly allow
toString() conversions.
Each of the three method call expressions below produce this error: "[Static
type checking] - Cannot find matching method
bugs.Groovy8488#m1(java.math.BigDecimal). Please check if the declared type is
correct and if the method exists."
Do we expect number literals (such as BigDecimal, BigInteger or even just
Double) to be acceptable arguments to methods that accept "int", "double" or
"String"? Is there some limited set of automatic conversions that STC should
support? Dynamic Groovy supports the m1 and m2 calls, but throws
MissingMethodException for m3.
@groovy.transform.CompileStatic
class STC {
void m1(int i) {}
void m2(double d) {}
void m3(String str) {}
void test() {
m1(1.0)
m2(1.0)
m3(1.0)
}
}
https://issues.apache.org/jira/browse/GROOVY-8488
https://issues.apache.org/jira/browse/GROOVY-9224