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

!instanceof inference does not work

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 3.0.7
    • None
    • Static Type Checker
    • None

    Description

      I have the following Groovy program

       

      @groovy.transform.CompileStatic
      class Main {
          static Integer bar(Object o) {
              if (o !instanceof Integer) {
                  return 0
              } else {
                  return o
              }
          }
      }
      

      Actual Behavior

      The program does not compile, and I get the following error.

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Main.groovy: 7: [Static type checking] - Cannot return value of type java.lang.Object on method returning type java.lang.Integer
       @ line 7, column 9.
                 o
                 ^
      
      1 error
      

      Expected Behavior

      Compile successfully.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              schaliasos Stefanos Chaliasos
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: