Unexpected treatment of tags in variants lazarus / 62-General ---------------------------------------------------------------------- 440bx · 2022-02-27 18:11 Hello, consider the following type declaration Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  SomeRecord          : record    case integer of      1 : (           a              : integer;          );      1 : (           b            : integer;          );      1 : (           c              : integer;          );      1 : (           d              : integer;        );  end; FPC doesn't complain that multiple variants are tagged with the same integer (strictly speaking the compiler doesn't need the tags to be different) but, Delphi (I've only tested with version 2) doesn't accept it (which seems to be the reasonable/strict action.) Thoughts and comments welcome. ---------------------------------------------------------------------- howardpc · 2022-02-27 21:34 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SomeRecord = recordcase Integer of   1: (a: Integer);   1: (b: Integer);   1: (c: Integer);   1: (d: Integer);end;is exactly equivalent to Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ThisRecord = record   z: Integer;end; The anonymous integer tags of 1, and the four apparently different fields a, b, c, d are all tautological. So although Delphi appears stricter, I would say the FPC is not incorrect to ignore the value of the case selector which is meaningless in this case, since although the four fields are given different names they all refer to the same memory location in the record. ---------------------------------------------------------------------- Bart · 2022-02-27 21:45 Quote from: howardpc on February 27, 2022, 10:34:15 pmThe anonymous integer tags of 1, and the four apparently different fields a, b, c, d are all tautological. This will also compile though: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  SomeRecord = record  case Integer of    1: (a: Integer);    1: (b: char);    1: (c: double);    1: (d: boolean);  end; Bart ---------------------------------------------------------------------- howardpc · 2022-02-27 21:56 @Bart True enough. However in this case the Pascal syntax introduces redundancy, since no case selectors are needed, but the syntax requires them. The compiler constructs the record according to the maximum field size required, and the programmer's field naming is sufficient to identify which type to select at runtime. The case selector can be ignored altogether. Nevertheless I certainly admit that it does look less than ideal that the compiler swallows this without complaint, even though no harm comes of it. ---------------------------------------------------------------------- 440bx · 2022-02-27 23:29 Just for the record, I used integer everywhere for copy/paste simplicity. I noticed the problem with a much more complicated structure that involved many types. ---------------------------------------------------------------------- PascalDragon · 2022-02-28 13:49 Quote from: 440bx on February 27, 2022, 07:11:34 pmThoughts and comments welcome. Please file a bug report. ---------------------------------------------------------------------- 440bx · 2022-02-28 15:49 Quote from: PascalDragon on February 28, 2022, 02:49:30 pmQuote from: 440bx on February 27, 2022, 07:11:34 pmThoughts and comments welcome. Please file a bug report. done.  https://gitlab.com/freepascal.org/fpc/source/-/issues/39605 ---------------------------------------------------------------------- PascalDragon · 2022-03-01 08:10 Quote from: 440bx on February 28, 2022, 04:49:11 pmQuote from: PascalDragon on February 28, 2022, 02:49:30 pmQuote from: 440bx on February 27, 2022, 07:11:34 pmThoughts and comments welcome. Please file a bug report. done.  https://gitlab.com/freepascal.org/fpc/source/-/issues/39605 Thank you. ---------------------------------------------------------------------- Bart · 2022-03-02 13:36 Just for fun: TP 6.0 actually accepts this. Bart