https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114055

--- Comment #2 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Created attachment 57497
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57497&action=edit
Proposed fix

The fix marks a constant created during the default BY clause of the FOR loop
as internal.  The type checker will always return true if checking against an
internal const.

$ cat forloopby.mod
MODULE forloopby ;


PROCEDURE init ;
CONST
   increment = CARDINAL (1) ;
VAR
   i: INTEGER ;
BEGIN
   FOR i := 0 TO 10 BY increment DO
   END
END init ;


BEGIN
   init
END forloopby.

 gm2 forloopby.mod 
forloopby.mod:10:8: error: In procedure ‘init’: type expression incompatibility
between ‘INTEGER’ and ‘CARDINAL’ detected between the designator ‘i’ and the BY
constant expression ‘increment’ in the FOR loop
   10 |    FOR i := 0 TO 10 BY increment DO
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~

It also succeeds when compiling a for loop with a subrange which does not
include 1.

$ cat forloopby2.mod 
MODULE forloopby2 ;

TYPE
   negative = [-10..-1] ;


PROCEDURE init ;
VAR
   i: negative ;
BEGIN
   FOR i := MIN (negative) TO MAX (negative) DO
   END
END init ;


BEGIN
   init
END forloopby2.

$ gm2 forloopby2.mod

Reply via email to