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

@CompileStatic improperly orders parameter types

    Details

      Description

      Given the following snippet

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class Foo {
      void isEqualTo(Number number) { println "Number" }
      void isEqualTo(Object number) { println "Object" }
      }
      
      @CompileStatic
      class Runner {
      void run() {
      new Foo().isEqualTo(4)
      }
      }
      
      new Runner().run()
      

      When you try to run it
      Then you get the following exception

      [Static type checking] - Reference to method is ambiguous. Cannot choose between [void Foo#isEqualTo(java.lang.Object), void Foo#isEqualTo(java.lang.Number)]
       at line: 13, column: 1
      

      And you would expect the thing to compile properly

        Attachments

          Activity

            People

            • Assignee:
              daniel_sun Daniel Sun
              Reporter:
              marcingrzejszczak Marcin Grzejszczak
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: