groovy
  1. groovy
  2. GROOVY-5231

Problem with @TupleConstructor with static type checking

    Details

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

      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()

        Issue Links

          Activity

          Hide
          CÚdric Champeau added a comment -

          The underlying problem is default argument values: the type checker doesn't verify that a call is possible with "missing" arguments.

          Show
          CÚdric Champeau added a comment - The underlying problem is default argument values: the type checker doesn't verify that a call is possible with "missing" arguments.

            People

            • Assignee:
              CÚdric Champeau
              Reporter:
              Guillaume Laforge
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: