Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10094

STC misses type checks on default arguments

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.15, 4.0.0-beta-1, 3.0.9
    • 4.0.0-beta-2, 3.0.20
    • Static Type Checker
    • None

    Description

      I have the following program

      class Foo {
        void bar(int x = "str") {
          System.out.println(x)
        }
      }
      class Main {
        public static void main(String[] args) {
          (new Foo()).bar()
        } 
      }
      

      Actual Behaviour

      Runtime error

      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)
      
      

      Expected Behaviour

      Compile-time error

       

      Tested against https://github.com/apache/groovy/commit/867aa7041cfc790d01828591f72996099ff2439f

      Attachments

        Activity

          People

            emilles Eric Milles
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: