mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Wrong result of unary - operation
#207
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @taichi-ishitani on GitHub (Sep 16, 2024).
Pkl will return the wrong result for the unary
-operation like below.The result of this operation should be
1but got-1.@bioball commented on GitHub (Sep 16, 2024):
Thanks for the report; definitely looks like bug. Haven't looked into it yet, but this looks parser related. Unary minus otherwise works as expected:
Produces:
@madrob commented on GitHub (Sep 16, 2024):
This is fun!
@DFrenkel commented on GitHub (Sep 19, 2024):
Double unary minus could be easily confused with a decrement.
Java, JavaScript, Golang, .NET all fail to compile
--1expression either expecting parentheses around(-1)or expecting a variable to be decremented instead of a literal.Increment/decrement
++and--are deprecated in Swift 2.2 and removed in Swift 3.Python, however, handles
x = --1correctly.I think pkl should follow the simplest solution and expect
++aor--ato fail with a clear message .An alternative is to start supporting prefix (and postfix for symmetry?) increments and decrements:
--ato fail whenais numerical literal--ato mean "decrease a by 1 and return the new value of a as result" whenais a variableWhat do you think?
@HT154 commented on GitHub (Sep 21, 2024):
This bug extends through parentheses as well:
A decrement operator of any kind seems like the wrong choice for Pkl as it implies some form of imperative mutation that doesn't exist in the language.
@bioball commented on GitHub (Oct 11, 2024):
Good point, @DFrenkel. I'm sympathetic to the idea that
--ashould hard-fail, because it might be confused with decrement.