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

@CompileStatic: A method which has default value parameter and generic return type will cause type checking error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.8, 2.4.0-rc-1, 2.4.1
    • 2.3.11, 2.4.2
    • Static Type Checker
    • None
    • Windows 7 64bit
      java version "1.7.0_71"
      Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

    Description

      Testcase as follow:

      import groovy.transform.CompileStatic
      import org.junit.Test
      
      class Bug1Base<T> {
      	T t
      
      	T get(a, b=0) {
      		return t
      	}
      }
      
      class Bug1 {
      	@Test
      	@CompileStatic
      	void test() {
      		Bug1Base<Integer> bug = new Bug1Base<Integer>(t:1)
      		Integer t = bug.get(1)
      		println t
      	}
      }
      

      It will cause type checking error as follow:

      Groovyc: [Static type checking] - Cannot assign value of type T to variable of type java.lang.Integer
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            druid0523 LibX
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: