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

STC: field and interface default method accessor property

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 5.0.0-alpha-9
    • Static Type Checker
    • None

    Description

      Consider the following:

      package p;
      public interface I {
        default Number getFoo() { return 42; }
      }
      
      class C implements p.I {
        private String foo
      }
      
      @groovy.transform.CompileStatic
      void test(C c) {
        def foo = c.foo
        print foo
      }
      test(new C())
      

      This script prints "42" but the inferred type of "c.foo" is String. Changing "def" to "Number" results in: Cannot assign value of type java.lang.String to variable of type java.lang.Number

      Attachments

        Activity

          People

            emilles Eric Milles
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: