From c95fa10824a1f9d05de165a08b87d1ffa82783b2 Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Sun, 12 Dec 2021 15:26:45 +0100 Subject: [PATCH] bug fix #2572 --- TestSuite/diapasons3.pas | 17 +++++++++-------- TestSuite/diapasons4.pas | 6 ++++++ bin/Lib/PABCSystem.pas | 15 ++++++++++++++- 3 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 TestSuite/diapasons4.pas diff --git a/TestSuite/diapasons3.pas b/TestSuite/diapasons3.pas index 1e8a6d743..bb99cfb62 100644 --- a/TestSuite/diapasons3.pas +++ b/TestSuite/diapasons3.pas @@ -1,11 +1,12 @@ -var a : 1..4; +var + a: 1..4; begin -a := 2; -a += 1; -assert(a=3); -a -= 1; -assert(a=2); -a *= 2; -assert(a=4); + a := 2; + a += 1; + assert(a = 3); + a -= 1; + assert(a = 2); + a *= 2; + assert(a = 4); end. \ No newline at end of file diff --git a/TestSuite/diapasons4.pas b/TestSuite/diapasons4.pas new file mode 100644 index 000000000..74788c3ea --- /dev/null +++ b/TestSuite/diapasons4.pas @@ -0,0 +1,6 @@ +begin + var r := 1..2; + assert(r <> nil); + r := nil; + assert(r = nil); +end. \ No newline at end of file diff --git a/bin/Lib/PABCSystem.pas b/bin/Lib/PABCSystem.pas index 8bcffc9f0..015ddde21 100644 --- a/bin/Lib/PABCSystem.pas +++ b/bin/Lib/PABCSystem.pas @@ -637,7 +637,20 @@ type static function operator in(x: integer; r: IntRange): boolean := (x >= r.l) and (x <= r.h); static function operator in(x: real; r: IntRange): boolean := (x >= r.l) and (x <= r.h); - static function operator=(r1,r2: IntRange): boolean := (r1.l = r2.l) and (r1.h = r2.h); + static function operator=(r1,r2: IntRange): boolean; + begin + var o1: object := r1; + var o2: object := r2; + if (o1 = nil) and (o2 = nil) then + Result := true + else if (o1 <> nil) and (o2 = nil) then + Result := false + else if (o1 = nil) and (o2 <> nil) then + Result := false + else + Result := (r1.l = r2.l) and (r1.h = r2.h); + end; + /// Возвращает True если диапазон пуст function IsEmpty: boolean := l>h;