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

@TypeChecked: Closure<String> no longer compatible with Closure<GString> argument

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.7
    • Fix Version/s: 4.0.0-alpha-3
    • Component/s: Compiler
    • Labels:
      None
    • Environment:
      Windows 10
      jdk-11.0.10.9-hotspot
      IntelliJ 2020.3.2

      Description

      Problem
      A Closure<String> is in Groovy 3 no longer compatible with a closure that returns a GString (or String|GString), even though GString is autoconverted
      to String in Groovy.

      Expected
      A Closure returning a GString or a String|GString should be compatible with Closure<String>

      Sample Code

      import groovy.transform.TypeChecked
      import org.junit.Ignore
      import org.junit.Test
      
      @TypeChecked
      class Groovy3_ClosureOfString_GString_Compatible {
      	@Test @Ignore
      	void 'Groovy 3-0-7 Closure with String return type not compatible with GString argument'() {
      		final x = 123
      		// Cannot find matching method execStringCls(Closure<groovy.lang.GString>)
      		assert execStringCls { "x=$x" } == 'x=123'
      		//assert execStringCls { "x=$x".toString() } == 'x=123'  // works
      	}
      
      	@Test @Ignore
      	void 'Groovy 3-0-7 Closure with String return type not compatible with GString argument 2'() {
      		final x = 123
      		// Cannot find matching method execStringCls(Closure<java.io.Serializable>)
      		assert execStringCls { false ? 'abc' : "x=$x" } == 'x=123'
      		//assert execStringCls { true ? 'abc' : "x=$x".toString() } == 'x=123' // works
      	}
      
      	String execStringCls(Closure<String> cls) {
      		cls()
      	}
      }
      

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              emge mgroovy

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h

                  Issue deployment