You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by paulk-asert <gi...@git.apache.org> on 2016/05/24 11:53:17 UTC

[GitHub] groovy pull request: GROOVY-7841: Assert fails when accessing part...

GitHub user paulk-asert opened a pull request:

    https://github.com/apache/groovy/pull/338

    GROOVY-7841: Assert fails when accessing particular primitive values \u2026

    \u2026with @CompileStatic

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/paulk-asert/groovy groovy7841

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/338.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #338
    
----
commit c7d106315226667248dca01af793bb24b96d8d97
Author: paulk <pa...@asert.com.au>
Date:   2016-05-24T11:52:12Z

    GROOVY-7841: Assert fails when accessing particular primitive values with @CompileStatic

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] groovy pull request: GROOVY-7841: Assert fails when accessing part...

Posted by paulk-asert <gi...@git.apache.org>.
Github user paulk-asert commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/338#discussion_r64549052
  
    --- Diff: src/main/org/codehaus/groovy/transform/sc/transformers/BooleanExpressionTransformer.java ---
    @@ -134,15 +134,19 @@ public void visit(final GroovyCodeVisitor visitor) {
                                 // int on stack
                             } else if (top.equals(ClassHelper.long_TYPE)) {
                                 MethodVisitor mv = controller.getMethodVisitor();
    -                            mv.visitInsn(L2I);
    +                            mv.visitInsn(LCONST_0);
    +                            mv.visitInsn(LCMP);
                                 controller.getOperandStack().replace(ClassHelper.boolean_TYPE);
                             } else if (top.equals(ClassHelper.float_TYPE)) {
                                 MethodVisitor mv = controller.getMethodVisitor();
    -                            mv.visitInsn(F2I);
    +                            mv.visitInsn(F2D);
    --- End diff --
    
    We probably could. In general, comparisons with floats are notoriously ugly, e.g. see:
    https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
    But given we are comparing against 0.0, it is probably an edge case that isn't as bad as the general case (but see 'Infernal zero' in the aforementioned link). A general recommendation is to use doubles instead of floats but I don't really know for sure whether it does in this case. My rationale was to look at what bytecode was produced from `assert floatValue != 0.0f` and then replicating that - which is where the `F2D` and `DCMPG` came from.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] groovy pull request: GROOVY-7841: Assert fails when accessing part...

Posted by paulk-asert <gi...@git.apache.org>.
Github user paulk-asert closed the pull request at:

    https://github.com/apache/groovy/pull/338


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] groovy pull request: GROOVY-7841: Assert fails when accessing part...

Posted by shils <gi...@git.apache.org>.
Github user shils commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/338#discussion_r64490605
  
    --- Diff: src/main/org/codehaus/groovy/transform/sc/transformers/BooleanExpressionTransformer.java ---
    @@ -134,15 +134,19 @@ public void visit(final GroovyCodeVisitor visitor) {
                                 // int on stack
                             } else if (top.equals(ClassHelper.long_TYPE)) {
                                 MethodVisitor mv = controller.getMethodVisitor();
    -                            mv.visitInsn(L2I);
    +                            mv.visitInsn(LCONST_0);
    +                            mv.visitInsn(LCMP);
                                 controller.getOperandStack().replace(ClassHelper.boolean_TYPE);
                             } else if (top.equals(ClassHelper.float_TYPE)) {
                                 MethodVisitor mv = controller.getMethodVisitor();
    -                            mv.visitInsn(F2I);
    +                            mv.visitInsn(F2D);
    --- End diff --
    
    Why not use a compare float operation here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] groovy pull request: GROOVY-7841: Assert fails when accessing part...

Posted by shils <gi...@git.apache.org>.
Github user shils commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/338#discussion_r64561363
  
    --- Diff: src/main/org/codehaus/groovy/transform/sc/transformers/BooleanExpressionTransformer.java ---
    @@ -134,15 +134,19 @@ public void visit(final GroovyCodeVisitor visitor) {
                                 // int on stack
                             } else if (top.equals(ClassHelper.long_TYPE)) {
                                 MethodVisitor mv = controller.getMethodVisitor();
    -                            mv.visitInsn(L2I);
    +                            mv.visitInsn(LCONST_0);
    +                            mv.visitInsn(LCMP);
                                 controller.getOperandStack().replace(ClassHelper.boolean_TYPE);
                             } else if (top.equals(ClassHelper.float_TYPE)) {
                                 MethodVisitor mv = controller.getMethodVisitor();
    -                            mv.visitInsn(F2I);
    +                            mv.visitInsn(F2D);
    --- End diff --
    
    Thanks for the explanation.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---