diff --git a/releasenotes.md b/releasenotes.md index 7d71b0139..93b322aff 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -50,6 +50,7 @@ - Fix the case where `\u` could crash the compiler on some platforms. - Designated initialization with ranges would not error on overflow by 1. - `io::read_fully` now handles unbounded streams properly. +- Crash when doing a type property lookup for const inline enums in some cases #2717. ### Stdlib changes - Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads. diff --git a/src/compiler/sema_name_resolution.c b/src/compiler/sema_name_resolution.c index c6ef21a1d..74073972d 100644 --- a/src/compiler/sema_name_resolution.c +++ b/src/compiler/sema_name_resolution.c @@ -1037,7 +1037,7 @@ Decl *sema_resolve_type_method(SemaContext *context, CanonicalType *type, const goto RETRY; case TYPE_ENUM: case TYPE_CONST_ENUM: - type = enum_inner_type(type); + type = enum_inner_type(type)->canonical; goto RETRY; default: UNREACHABLE diff --git a/test/test_suite/enumerations/const_enum.c3 b/test/test_suite/enumerations/const_enum.c3 new file mode 100644 index 000000000..fa536247a --- /dev/null +++ b/test/test_suite/enumerations/const_enum.c3 @@ -0,0 +1,12 @@ +import std::io; + +enum MyEnum : const inline CInt +{ + FOO = 1, + BAR = 5, + BAZ = 9, +} +fn void main() +{ + io::printn(MyEnum.lookup(2)); // #error: No method or inner struct/union 'MyEnum.lookup' found +} \ No newline at end of file