Skip to content

set of range assignment fails to range check

Referenced from https://forum.lazarus.freepascal.org/index.php/topic,70094.msg545886.html#msg545886

The compiler fails to perform a range check when a range is defined and a set of range is defined and assigned to:

{$mode objfpc}{$H+}{$R+}
type
  TmyRange = 1..10;
var
  x: integer;
  Mark: set of TmyRange;
begin
  Mark := [5,11];{<-Why doesn't 11 cause a range check error?}
  for x in Mark do write(x,' IN Mark');
end.

Tested with both 3.2.2 and 3.3.1 Win64 and Linux64 It does not matter if the set is a var or derived from a set type.

Note for in do works fine and does not reach 11. Include etc, als work fine and does range check, it is only the assignment.

Edited by Thaddy de Koning
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information