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

Problem with @TupleConstructor with static type checking

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-beta-3
    • Component/s: Static Type Checker
    • Labels:
      None

      Description

      When using the @TupleConstructor with the static type checking, it doesn't like when a constructor without all the fields is used.
      Consider the following example:

      import groovy.transform.*
      
      @TupleConstructor
      @TypeChecked
      class Person {
          String name, city
          static Person create() {
              new Person("Guillaume")
          }
      }
      
      Person.create()
      

      The type checker complains because it could not find a zero-arg constructor:

      [Static type checking] - Cannot find matching method Person#<init>(java.lang.String)
       at line: 8, column: 9
      

      But actually, @TupleConstructor allows to use less args than all the declared.
      Person can be instantiated with new Person("Guillaume", "Paris"), new Person("Guillaume"), or even new Person()

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                melix Cédric Champeau
                Reporter:
                Guillaume Guillaume Delcroix
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: