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

type checker should use superclass bound when expected by generics

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.3
    • 4.0.0-alpha-3
    • Static Type Checker
    • None

    Description

      I believe this is a special case of a general problem with generics and the type checker.

      When I attempt to call a method doSomething(Map<String,Object> params) with a Groovy inline map, the type checker constructs the map's types as the immediate greatest-common-superclass of the values provided. For example, this map:

      [ val1: 3, val2: 5 ]
      

      is always considered to be a LinkedHashMap<String,Integer>, which can't be passed to the above method. In some, but not all, cases using an explicit as Map<String,Object> will work.

      In the circumstance where an inline map or other generic collection is assigned to a variable or used as a method parameter, the type checker should be able to relax the inferred generic type bound to match the expected bound.

      Attachments

        Activity

          People

            emilles Eric Milles
            chrylis Christopher Smith
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: