No implicit cast for enums?

Hi,

I just wanted to ask: Is there no implicit cast for enums in general? It is not listed here in the documentation (https://odin-lang.org/docs/overview/#implicit-type-conversions) and my example from below requires an explicit cast.

package main

import "core:fmt"

main :: proc() {
	OpCode :: enum u8 {
		OP_RETURN,
	}

	code: [dynamic]u8

	append(&code, OpCode.OP_RETURN) // this doesn't work
	append(&code, cast(u8)OpCode.OP_RETURN) // requires explicit cast

	fmt.printf("%d", code[0])
}
1 Like

Yes, you must cast enums.

My original reply contained a link to the implicit type conversions, but my brain completely blanked that you already linked it and checked it out. :sweat_smile:
I am a selective reader.

1 Like

Thanks, great to know :slight_smile:

1 Like

The general rule in Odin is to assume there are no implicit casts whatsoever.

4 Likes

This is actually quite nice since it makes a lot of things more intuitive.

1 Like