Skip to content

Operator precedence for math_number (JS/PHP generators) #1563

Description

@jschanker

Problem statement

Bug Report: The JavaScript/PHP generators for math_number currently return ORDER_ATOMIC for all numbers when they should be returning ORDER_UNARY_NEGATION for negative numbers. In JavaScript, this can cause an issue if you e.g., extend Number.prototype by adding an abs method for absolute value and want to have a corresponding abs block (not for use in production, educational purposes only!) For example:

image

Expected Behavior

The generated code for the block above should be (-5).abs() so that it evaluates to 5.

Actual Behavior

With ORDER_ATOMIC, the above block would generate the code -5 .abs(), which would incorrectly produce -5 since the -5 block is "ripped apart" as described in Operator Precedence | Blockly | Google Developers.

Operating System and Browser

All

Additional Information

The math_number block generator for Dart, Python, and Lua account for negative numbers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions