Skip to content

Unclear error "Duplicate field index" with enum array. #6042

@Chamberlain91

Description

@Chamberlain91

Context

Was attempting to use an enum array [E]V and encountered a confusing "duplicate keys" issue when there are no duplicate keys.

Odin:    dev-2025-12:60130b87b
OS:      Windows 11 Home Basic (version: 25H2), build 26200.7462
CPU:     AMD Ryzen 9 9900X 12-Core Processor
RAM:     63109 MiB
Backend: LLVM 20.1.0

Expected Behavior

No error, all keys are unique.

Current Behavior

Error of "Duplicate field index" not indicating which duplicate key.

Failure Information (for bugs)

Seems to be related to an alias enum member and an enum member that is a subset of another members name. Not sure exactly, thought it was a prefix thing when I posted but repro without it.

Edit: Determined to be not a bug, but an improved diagnostic message about which names are duplicated on which value may illuminate the issue more clearly.

Steps to Reproduce

package bug

main :: proc() {}

Key_Array := [Keys]int {
	.Key_0           = 0,
	.Key_1           = 0,
	.Key_1_With_More = 0, // Move this line up and down
	.Key_2           = 0,
}

Keys :: enum {
	Key_0,
	Key_1,
	Key_1_With_More, // This having a prefix of Key_1
	Default = Key_1, // Which has this alias member, causing Key_2 to fail.
	Key_2,           // Or Key_1_With_More, depending on order.
}

or

package bug

main :: proc() {}

Key_Array := [Keys]int {
	.Apple  = 0,
	.Banana = 1,
	.Orange = 2,
	.Tomato = 3, // Error here
}

Keys :: enum {
	Apple,
	Banana,
	Orange,
	Default = Apple,
	Tomato,
}

Failure Logs

C:/Projects/odin-bug/bug.odin(9:3) Error: Duplicate field index .Key_2 for enumerated array literal 
        .Key_2           = 0, 
         ^~~~~~~~~~~~~~~~~~^ 

or

C:/Projects/odin-bug/bug.odin(9:3) Error: Duplicate field index .Tomato for enumerated array literal 
        .Tomato = 3, 
         ^~~~~~~~~^ 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions