[
https://issues.apache.org/jira/browse/GROOVY-10094?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King closed GROOVY-10094.
------------------------------
> STC misses type checks on default arguments
> -------------------------------------------
>
> Key: GROOVY-10094
> URL: https://issues.apache.org/jira/browse/GROOVY-10094
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Affects Versions: 2.5.15, 4.0.0-beta-1, 3.0.9
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.0-beta-2
>
>
> h3. I have the following program
> {code:java}
> class Foo {
> void bar(int x = "str") {
> System.out.println(x)
> }
> }
> class Main {
> public static void main(String[] args) {
> (new Foo()).bar()
> }
> }
> {code}
> h3. Actual Behaviour
> Runtime error
> {code:java}
> Exception in thread "main"
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast
> object 'fda' with class 'java.lang.String' to class 'int'
> at
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:172)
> at
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.intUnbox(DefaultTypeTransformation.java:81)
> at Foo.bar(test.groovy)
> at Main.main(test.groovy:10)
> {code}
> h3. Expected Behaviour
> Compile-time error
>
> Tested against
> https://github.com/apache/groovy/commit/867aa7041cfc790d01828591f72996099ff2439f
--
This message was sent by Atlassian Jira
(v8.20.1#820001)