Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missleading error(s) when working with malformed bitset initializers #4742

Open
SaculRennorb opened this issue Jan 22, 2025 · 0 comments
Open

Comments

@SaculRennorb
Copy link

SaculRennorb commented Jan 22, 2025

This is a bit of a more general issue, but some error messages could really use some improvements.

This is not a bug, the compiler is correct here, but the messages are rather confusing (unspecific):

package main
main :: proc() { }


A :: enum { A, B, C, D };
E :: bit_set[A; i32]
F :: E{ .A , .B }


xx :: E{ .C , .D , .F } // malformed 1 

xxx :: i32(E{ .C , .D , .F }) // malformed 2

This is malformed, and the compiler will give you the following errors:
malformed 1:

C:/Users/Rennorb/source/tests/test.odin(9:7) Error: 'E{.C, .D, .F}' is not a compile-time known constant 
        xx :: E{ .C , .D , .F } 
              ^~~~~~~~~~~~~~~~^ 
 
C:/Users/Rennorb/source/tests/test.odin(9:21) Error: Undeclared name 'F' for type 'enum int {A, B, C, D}'
        xx :: E{ .C , .D , .F } 
                            ^ 
        Suggestion: Did you mean? 
                A
                B
                C
                D

This is correct ofcourse, but the first message is completely pointless, even though it gets emitted first. It is like saying "this program is malformed". Technically true, but adds nothing of value.

The second one is a lot worse though imo:
malformed 2:

C:/Users/Rennorb/source/tests/test.odin(11:8) Error: Invalid declaration value 'i32(E{.C, .D, .F})'
        xxx :: i32(E{ .C , .D , .F }) 
               ^~~~~~~~~~~~~~~~~~~~~^ 
 
C:/Users/Rennorb/source/tests/test.odin(11:12) Error: Cannot cast 'E{.C, .D, .F}' as 'i32' from 'bit_set[A; i32]'
        xxx :: i32(E{ .C , .D , .F }) 
                   ^~~~~~~~~~~~~~~~^ 
 
C:/Users/Rennorb/source/tests/test.odin(11:26) Error: Undeclared name 'F' for type 'enum int {A, B, C, D}'
        xxx :: i32(E{ .C , .D , .F }) 
                                 ^ 
        Suggestion: Did you mean? 
                A
                B
                C
                D

Again, technically true, but on an intuitive level the declaration is not invalid. Its just that .F is not a member of the enum, but a separate "union" of flags.
The second error is also only technically true, but only because (i assume) the declaration gets marked as invalid and therefore cannot be cast. For all intents and purposes this error is worse than pointless, because it hides the actual issue. You can cast a bitset(i32) to i32 just fine.
Only on the last line the actual error is stated: F is not a member of the enum.

All of this is incredibly noisy and reminds me of cpp errors, which i hoped to get away from.
In both cases the last error is completely sufficient, and everything else is plain noise.

odin report:
Useful information to add to a bug report:

    Odin:    dev-2024-12-nightly:cf53404
    OS:      Windows 10 Enterprise N (version: 20H2), build 19042.1466
    CPU:     Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz
    RAM:     65470 MiB
    Backend: LLVM 18.1.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant