You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Thodoris Sotiropoulos (Jira)" <ji...@apache.org> on 2021/05/18 11:56:00 UTC

[jira] [Created] (GROOVY-10094) STC misses type checks on default arguments

Thodoris Sotiropoulos created GROOVY-10094:
----------------------------------------------

             Summary: 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
            Reporter: Thodoris Sotiropoulos


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.3.4#803005)