[ https://issues.apache.org/jira/browse/GROOVY-7608?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sean Gilligan updated GROOVY-7608: ---------------------------------- Description: If I create a subclass of {{Number}} that is implemented internally with a decimal value, e.g. using a {{BigDecimal}} even if I implement {{compareTo()}}, Groovy will convert my numbers to {{Integer}} before comparison. {code} given: def one = MyNumberSubclass.of(1) def oneptone = MyNumberSubclass.of(1.1) then: one == onptone // passes when it shouldn't! oneptone == oneptone // fails when it shouldn't! {code} This is a critical issue for anyone creating a DSL that has custom numeric types (e.g. for currency handling) and wants to compare them with {{==}}. Specifically this problem occurs with implementations of {{NumberValue}} in JSR354 aka *JavaMoney*. I can provide some test cases for this if needed and am interesting in working to contribute a fix. was: If I create a subclass of {{Number}} that is implemented internally with a decimal value, e.g. using a {{BigDecimal}} even if I implement {{compareTo()}}, Groovy will convert my numbers to {{Integer}} before comparison. {code} given: def one = MyNumberSubclass.of(1) def oneptone = MyNumberSubclass.of(1.1) then: one == onptone // passes when it shouldn't! oneptone == oneptone // fails when it shouldn't! {code} This is a critical issue for anyone creating a DSL that has custom numeric types (e.g. for currency handling) and wants to compare them with {{==}}. Specifically this problem occurs with implementation so {{NumberValue}} in JSR354 aka *JavaMoney*. I can provide some test cases for this if needed and am interesting in working to contribute a fix. > Comparison of decimal subclasses of Number with == fails > -------------------------------------------------------- > > Key: GROOVY-7608 > URL: https://issues.apache.org/jira/browse/GROOVY-7608 > Project: Groovy > Issue Type: Bug > Components: groovy-runtime > Affects Versions: 2.4.4 > Reporter: Sean Gilligan > > If I create a subclass of {{Number}} that is implemented internally with a > decimal value, e.g. using a {{BigDecimal}} even if I implement > {{compareTo()}}, Groovy will convert my numbers to {{Integer}} before > comparison. > {code} > given: > def one = MyNumberSubclass.of(1) > def oneptone = MyNumberSubclass.of(1.1) > then: > one == onptone // passes when it shouldn't! > oneptone == oneptone // fails when it shouldn't! > {code} > This is a critical issue for anyone creating a DSL that has custom numeric > types (e.g. for currency handling) and wants to compare them with {{==}}. > Specifically this problem occurs with implementations of {{NumberValue}} in > JSR354 aka *JavaMoney*. > I can provide some test cases for this if needed and am interesting in > working to contribute a fix. -- This message was sent by Atlassian JIRA (v6.3.4#6332)