openmultiplayer / openmultiplayer/compiler

Tagged arrays not being initialized correctly with `...` syntax

Open
#10 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
22
Forks
17
PR merge metrics
No merged PRs in 30d

Description

Compiler version: Pawn compiler 3.10.11 downloaded from open.mp v1.4.0.2779 server build

When initializing an array using a tagged enum size with the ellipsis (...) syntax, the array is not being properly initialized. Specifically, elements after the first one are set to 0 instead of being repeated as expected.

MVCE:

enum e_TEST_ENUM {
	TEST_ITEM_1,
	TEST_ITEM_2,
	TEST_ITEM_3,
	TEST_ITEM_4
};

new NotWorking[e_TEST_ENUM] = { 5, ... };

const TEST_ENUM_SIZE = _:e_TEST_ENUM;
new Working[e_TEST_ENUM:TEST_ENUM_SIZE] = { 5, ... };

#assert sizeof NotWorking == sizeof Working

main() {
	for(new i = 0; i != sizeof NotWorking; ++ i) {
		printf("%d, %d", NotWorking[e_TEST_ENUM:i], Working[e_TEST_ENUM:i]);
	}
}

Output:

5, 5  
0, 5  
0, 5  
0, 5  

Expected behavior:

5, 5  
5, 5  
5, 5  
5, 5  

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the MVCE with Pawn compiler 3.10.11 and compare the tagged enum-size initialization with the integer-size form. Trace the compiler's handling of { 5, ... } for both declarations; done when the tagged form repeats 5 for every element and matches the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.