[ 
https://issues.apache.org/jira/browse/GROOVY-11761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18022552#comment-18022552
 ] 

Stephen Albrecht commented on GROOVY-11761:
-------------------------------------------

Thanks for the reply and the workaround suggestions. 1 and 2 both work to fix 
this example case. Will have to see about updating that lib...

Seems like this is intended breaking change behavior and is not covered by the 
fallback logic.

> mod overloads in older Groovy library fail in Groovy 5
> ------------------------------------------------------
>
>                 Key: GROOVY-11761
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11761
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 5.0.1
>            Reporter: Stephen Albrecht
>            Priority: Major
>
> I found this issue in GrooCSS, an older library for writing CSS in Groovy 
> with a DSL. It depends on Groovy 2.5.8 but using it with newer versions 
> worked until 5.0.1.
> Possibly related to GROOVY-10800 mentioned in release notes: "In Groovy 5, 
> operator overloading for {{%}} is now handled by the {{remainder}} method. 
> Fallback behavior is supported and workarounds exist for folks already using 
> the {{mod}} method."
> example build.gradle dependencies
> {code:java}
> dependencies {
>     implementation 'org.apache.groovy:groovy:4.0.28'
>     implementation 'org.groocss:groocss:1.0-GA'
> }{code}
> This simple program outputs some CSS.
> {code:java}
> package org.example
> import org.groocss.GrooCSS
> import org.groocss.Selector
> static void main(String[] args) {
>     println GrooCSS.process {
>         keyframes('fadeOutBackground') {
>             0 % { backgroundColor blue }
>         }
>         a.foo {
>             color red
>         }
>         Selector s = a % link
>         s.foo {
>             extend(a.foo)
>         }
>     }.toString()
> } {code}
> Output (Groovy 4.0.28)
> {code:java}
> a.foo,a:link.foo {
>     color: Red;
> }
> @keyframes fadeOutBackground {
>     0% {
>         background-color: Blue;
>     }
> }@-webkit-keyframes fadeOutBackground {
>     0% {
>         background-color: Blue;
>     }
> }{code}
>  
> Updating to Groovy 5.0.1 breaks at runtime on the mod overload for keyframes
> {code:java}
> groovy.lang.MissingMethodException: No signature of method: remainder for 
> class: java.lang.Integer is applicable for argument types: 
> (org.example.Main$_main_closure1$_closure2$_closure5) values: 
> [org.example.Main$_main_closure1$_closure2$_closure5@24fabd0f]
> Possible solutions: remainder(java.lang.Number)
>  at org.example.Main$_main_closure1$_closure2.doCall(Main.groovy:10)
>  at org.groocss.GrooCSS.kf(GrooCSS.groovy:368)
>  at org.groocss.GrooCSS.keyframes(GrooCSS.groovy:361)
>  at org.example.Main$_main_closure1.doCall(Main.groovy:9) {code}
> defined 
> [here|https://github.com/adamldavis/groocss/blob/develop/src/main/groovy/org/groocss/ext/NumberExtension.groovy#L62]
> {code:java}
> class NumberExtension {
>     // ... other overloads
>     static KeyFrames mod(
>         Integer n,
>         @DelegatesTo(value=StyleGroup, strategy = Closure.DELEGATE_FIRST) 
> Closure frameCl
>     ) {
>         def css = GrooCSS.threadLocalInstance.get()
>         if (css) css.currentKf.frame(n, frameCl)
>     }
> }{code}
> If you comment out the keyframes call, the result of `a % link` now returns 
> null when it used to return a Selector object. That mod method is defined 
> [here|https://github.com/adamldavis/groocss/blob/develop/src/main/groovy/org/groocss/Selector.groovy#L145]:
> {code:java}
> class Selector extends Selectable {
>     // others
>     Selector mod(PseudoClass pc) {
>         new Selector("$value$pc", owner)
>     }
> }{code}
>  
>  
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to