From: "byroot (Jean Boussier) via ruby-core" Date: 2023-04-06T08:25:11+00:00 Subject: [ruby-core:113149] [Ruby master Bug#19583] Unary minus inconsistency when used with variables and literals Issue #19583 has been updated by byroot (Jean Boussier). Status changed from Open to Closed Yeah, I don't think this is a bug, and even if we decided another precedence would have been better, changing it would break way too much code. ---------------------------------------- Bug #19583: Unary minus inconsistency when used with variables and literals https://bugs.ruby-lang.org/issues/19583#change-102684 * Author: hurricup (Alexandr Evstigneev) * Status: Closed * Priority: Normal * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- This feels a bit inconsistent and I could not find an explanation. This is fine and `-` has higher precedence than `.` ``` -2.upto 0 do |arg| puts arg end ``` But this is not working, won't even compile (requires parens): ``` var = 2 -var.upto 0 do |arg| puts arg end ``` I presume that in the first example there is no unary minus operation, just negative literal. Ok, according to this - my assumption is correct. The question is - why? ``` def some puts -2 a = 42 puts -a end puts RubyVM::InstructionSequence.of(method :some).disasm ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/