odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.59k stars 575 forks source link

Varags & bit_set collision in proc signatures #2361

Open jon-lipstate opened 1 year ago

jon-lipstate commented 1 year ago

I'm having an issue with varags & bit_sets colliding. At the root of the issue, the varag is prior in the signature than the set. An example of this (though not ambiguous to the compiler) is core's fmt.aprint.

Usage Code: push_op(main, .mov, .RAX, .RCX) Working Signature: push_op :: proc(p: ^Procedure, m: Mneumnoic, args: ..RMI) { Non-Working Signature: push_op :: proc(p: ^Procedure, m: Mneumnoic, args: ..RMI, prefixes: Prefixes = {}) { Resulting Error:

ojitsu.odin(26:29) Error: Invalid type 'bit_set[Prefix_Flag]' for implicit selector expression '.RCX'
        push_op(main, .mov, .RAX, .RCX)
                                   ^~^

Temp Fix, though annoying: push_op(main, .mov, .RAX, GeneralPurpose.RCX) (Fully specified enum is no longer confused for the bit_set)

For completeness, the enums/bit_set are:

Prefixes :: bit_set[Prefix_Flag]
Prefix_Flag :: enum {...}
GeneralPurpose :: enum {...}
RMI :: union { GeneralPurpose, Mem, Imm, }
Kelimion commented 1 year ago

Have you tried packing the varargs together into one argument? push_op(main, .mov, {.RAX, .RCX})

jon-lipstate commented 1 year ago

I think I just have an edge case for the compiler (union/enum varag followed by a bit_set[enum]).

Compiler does not like it with or without the prefixes arg:

ojitsu.odin(26:22) Error: Invalid compound literal type 'RMI'
        push_op(main, .mov, {.RAX, .RCX})
                            ^~~~~~~~~~~^