POINTER TO ARRAY [untagged] accepted as the tagged ARRAY

Post Reply
Zorko
Posts: 26
Joined: Tue Sep 17, 2013 10:13 pm
Location: Ukraine
Contact:

POINTER TO ARRAY [untagged] accepted as the tagged ARRAY

Post by Zorko »

My colleague faced this problem in CPfront.

Code: Select all

MODULE Test;
  IMPORT SYSTEM;

  VAR
    s: POINTER TO ARRAY [untagged] OF SHORTCHAR;

  PROCEDURE Call (IN s: ARRAY OF SHORTCHAR);
  END Call;

BEGIN
  Call(s)
END Test.
CPfront allows this code and even generates some representation in C language, which of course will not work correctly.

BlackBox compiler found the error in the correct place, although the marker is at the beginning of the line, not where the parameter is. But that's not the problem.

The fact is that this check performs at the back-end level (in procedures Index & VarParDynArr of the module DevCPC486), although it would be best to do this check at the level of the front-end too. If that check was done in front-end, the error would not appear in CPfront.

I propose such a correction.
Attachments
DynArrParCheck.png
Last edited by Zorko on Tue May 28, 2019 11:07 pm, edited 2 times in total.
Zorko
Posts: 26
Joined: Tue Sep 17, 2013 10:13 pm
Location: Ukraine
Contact:

Re: POINTER TO ARRAY [untagged] accepted as the tagged ARRAY

Post by Zorko »

P.S. I foresee disputes that any fix should introduce new functionality or fix existing problems. But it's a really existing problem that the validation that needs to be done at the foreground level, since it involves type checking, takes it to the background. It's like trying to plug a crack.

I am a big supporter of the approach that every problem should be solved in the place of its occurrence, and nowhere else.

Thank you for your work!
Zorko
Posts: 26
Joined: Tue Sep 17, 2013 10:13 pm
Location: Ukraine
Contact:

Re: POINTER TO ARRAY [untagged] accepted as the tagged ARRAY

Post by Zorko »

Note: an untagged array with an explicitly specified length is equal to a tagged:

Code: Select all

VAR
  s: POINTER TO ARRAY [untagged] 10 OF SHORTCHAR;

PROCEDURE Call (a: ARRAY OF SHORTCHAR);
END Call;

BEGIN
  Call(s);  (* <- compatible *)
I didn't know that, and my correction above doesn't take that into account.
luowy
Posts: 87
Joined: Thu Dec 17, 2015 1:32 pm

Re: POINTER TO ARRAY [untagged] accepted as the tagged ARRAY

Post by luowy »

Hi Oleg,
As you pointed out, the first one can be patched at the front end;I have done it some time ago; I post it to your github;

but I don't think the second one is a bug:
for the untagged array have provided the enough info:the addr of array and the length of array, same as a tagged array;
if you dasm the code you will find the truth; Although it looks a bit weird;

luowy
Zorko
Posts: 26
Joined: Tue Sep 17, 2013 10:13 pm
Location: Ukraine
Contact:

Re: POINTER TO ARRAY [untagged] accepted as the tagged ARRAY

Post by Zorko »

Very nice patch, Wening Luo! I tested it and it works fine.

Since the module DevCPB is not included in CPfront, I can't use your patch directly, so I have to make a fix in back-end too, as in BlackBox now. In this case, BlackBox can be a host system for CPfront with your patch, and without it. Everything will work. I am truly grateful to you for your help.
Post Reply