Menu ▾ ▴

#1302 Level-88 under an OCCURS gets the wrong subscript count when copied by TYPE or SAME AS

unclassified
open
nobody
None
5 - default
2026-11-05
2026-11-05
No

When a TYPEDEF contains a table whose entry has a level-88 condition-name, the condition-name cannot be subscripted through an item declared with that type, although the data item takes the subscript. SAME AS does the same.

To reproduce

typ88.cob (attached, free format):

IDENTIFICATION DIVISION.
PROGRAM-ID. TYP88.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 T-TAB IS TYPEDEF.
   05 T-E PIC X OCCURS 2 TIMES.
      88 T-Y VALUE "Y".
01 A TYPE T-TAB.
PROCEDURE DIVISION.
    MOVE "NN" TO A
    SET T-Y OF A (2) TO TRUE
    IF T-Y OF A (2) DISPLAY "A " A END-IF
    STOP RUN.
cobc -x -free -std=cobol2014 -o typ88 typ88.cob

What happens

3.2.0 and 3.3-dev r5751 both stop with (source excerpts omitted)

typ88.cob:11: error: 'T-Y' cannot be subscripted
typ88.cob:12: error: 'T-Y' cannot be subscripted

The same happens without -std. MOVE "Y" TO T-E OF A (2) compiles, and SET T-Y OF A TO TRUE, with no subscript, compiles and sets the first occurrence. typ88n.cob and typ88o.cob, attached, show the same for a TYPE inside the TYPEDEF ('T-ON' cannot be subscripted) and for an item with its own OCCURS and that TYPE, where T-Y OF B-ROW (3, 2) gets 'T-Y' requires one subscript, and same88.cob the same for SAME AS ('S-Y' cannot be subscripted).

What should happen

The program should print A NY. A TYPE clause acts "as though the data description identified by type-name-1 had been coded in place of the TYPE clause" (ISO/IEC 1989:2023 13.18.57.4 general rule 1), and the type declaration includes its condition-name entries (13.18.58.4 general rule 1). So T-Y's conditional variable T-E has an OCCURS clause, and T-Y takes one subscript (8.4.2.3.3 syntax rules 2 and 3). The same in 2002 and in the 2014 FCD.

Why it happens

In cobc/field.c, copy_into_field_recursive copies an item of the type, then its level-88 entries (copy_validation) and its children, and only at the end sets the copy's indexes to source->indexes + outer_indexes. cb_build_field_tree gives a new condition-name the indexes of its parent, so it gets the count from before that assignment: 0 in typ88, one too few in typ88o.

Proposed fix

The attached n10-type-condition-name-subscript.patch (against 3.3-dev r5751) moves that assignment to the top of copy_into_field_recursive, so the level-88 entries and children see the parent's final count. SAME AS goes through the same copy, so the patch fixes it too. With it the four programs print A NY, A NY, B NNNNNY and S2 NY. cobc now also refuses SET T-Y OF A TO TRUE, with no subscript ('T-Y' requires one subscript), as it does for a table declared without TYPE, and SET T-Y OF B-ROW (2) TO TRUE in typ88o's layout ('T-Y' requires 2 subscripts), which unpatched compiles and applies to occurrence (1, 2).

It adds the testsuite case "TYPEDEF with condition-name in a table" to run_fundamental.at, with ChangeLog entries. make check: 1373 expected, 9 skipped, 0 failed (1372 unpatched); the new test fails without the patch.

bugs #738, "access to Level-88 declaration in Typedef not possible", may be related. A comment there says its case passes on 3.3-dev, and this one does not, so we report it separately. Level-88 copying for TYPE (copy_validation, cobc/ChangeLog 2023-07-20) came after #738 was filed, which may be why its case now passes.

Details

GnuCOBOL 3.2.0 (Ubuntu gnucobol3 3.2-4build1) and 3.3-dev r5751 (CI snapshot 3.3-dev.138 of 2026-10-29), x86_64 Linux, both run 2026-11-04.

5 Attachments

Discussion


Log in to post a comment.