Unary minus on a record without an operator compiles and segfaults
type R = record x, y: Double; end;
var a, b: R;
b := -a; { fpc: Error: Operator is not overloaded: - "R" pxx: rc 0, then SIGSEGV }
Fix
In ParseFactor's tkMinus arm, after UnaryOpOverloadCall declines, a
tyRecord/tyClass operand is refused with fpc's message (the UCls name when
there is one). Nil Python is excluded, since its -obj never reaches this
AN_NEG.
lib/rtl/ucomplex.pas gains operator - (z1: complex) z: complex, which fpc's
ucomplex declares (packages/rtl-extra/src/inc/ucomplex.pp:151). The pinned
compiler builds the new unit.
lib/rtl/vecmath.pas has no unary minus for its vectors. It is pxx's own unit,
so adding one is a feature and not parity; -v is now a compile error there
rather than a crash.
Tests
- test_unary_minus_on_a_record_with_an_operator: a global
operator -, an advanced record'sclass operator -, ucomplex's-z, anda <> -a/a = -(-a)on both. Its expected output is fpc 3.2.2's; it passes on six targets. - test_unary_minus_on_a_record_needs_an_operator: the refusal row, with fpc's exact message.