Bookstore

Recent

Author Topic: A question regarding "Set type"  (Read 282 times)

RuudB

  • New Member
  • *
  • Posts: 17
A question regarding "Set type"
« on: February 21, 2020, 06:02:47 pm »
I was playing with his set in V3.0.2:
 
const
  s = [47, '0'];

I noticed that TP7 doesn't accept this: all members have to be of the same type. NP for me, I can live with that :)

The next one:

  s = ['0', 49];

was NOT accepted, with the error that a char was expected. The documentation at https://www.freepascal.org/docs-html/current/ref/refsu16.html#x40-580003.3.3 doesn't mention anything about the possibility of mixing ordinal types.
If it is not possible, the first example should have raised an error, if it is possible, the second one should have been accepted. Unless I have missed something.

Can anybody shed some light on this, please? Many thanks!

FYI, I'm not complaining, just pure curiosity.

Handoko

  • Hero Member
  • *****
  • Posts: 3434
  • My goal: build my own game engine using Lazarus
Re: A question regarding "Set type"
« Reply #1 on: February 21, 2020, 07:18:27 pm »
To me, that is a bug. Please report to Bugtracker.
http://bugs.freepascal.org/set_project.php?project_id=6

Roland57

  • New Member
  • *
  • Posts: 35
Re: A question regarding "Set type"
« Reply #2 on: February 21, 2020, 07:24:08 pm »
IMHO it isn't a problem.

Code: Pascal  [Select]
  1. const
  2.   s = [47, '0'];
  3.  
  4. begin
  5.   WriteLn('/' in s); // TRUE
  6. end.

But I don't know why this isn't accepted:

Code: Pascal  [Select]
  1. const
  2.   s = ['0', 47];
« Last Edit: February 21, 2020, 07:26:42 pm by Roland57 »

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8065
Re: A question regarding "Set type"
« Reply #3 on: February 21, 2020, 07:27:03 pm »
I first thought it was a bug, but strictly speaking since "S" is untyped, and if you take "S" as a array of variant, it is correct syntax

Handoko

  • Hero Member
  • *****
  • Posts: 3434
  • My goal: build my own game engine using Lazarus
Re: A question regarding "Set type"
« Reply #4 on: February 21, 2020, 07:28:30 pm »
But why I got no error on the first one but compile-time error on the second one?

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8065
Re: A question regarding "Set type"
« Reply #5 on: February 21, 2020, 07:49:55 pm »
But why I got no error on the first one but compile-time error on the second one?

No idea. I thought maybe because char is not a variant type, but it doesn't accept '01' either.

lucamar

  • Hero Member
  • *****
  • Posts: 2579
Re: A question regarding "Set type"
« Reply #6 on: February 21, 2020, 08:52:29 pm »
But why I got no error on the first one but compile-time error on the second one?

Just a guess but it may be that the compiler finds the first member is a char and supposes it is a set of char/string (and waits to see which of the two). Whether that makes sense is anyones guess ...
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.6/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.