From 1634217fc422c1e8b63b65a37c099c1c40177e0d Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Mon, 25 Aug 2025 16:39:17 +0200 Subject: [PATCH] Grabbing (missing) methods on function pointers would cause crash #2434. --- releasenotes.md | 1 + src/compiler/sema_name_resolution.c | 1 + .../test_suite/methods/method_on_non_valid_type.c3 | 14 ++++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 test/test_suite/methods/method_on_non_valid_type.c3 diff --git a/releasenotes.md b/releasenotes.md index cd69f62bf..fefb509dc 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -67,6 +67,7 @@ - `has_tagof` on tagged lambdas returns false #2432 - Properly add "inlined at" for generic instantiation errors #2382. - Inlining a const as an lvalue would take the wrong path and corrupt the expression node. +- Grabbing (missing) methods on function pointers would cause crash #2434. ### Stdlib changes - Add `==` to `Pair`, `Triple` and TzDateTime. Add print to `Pair` and `Triple`. diff --git a/src/compiler/sema_name_resolution.c b/src/compiler/sema_name_resolution.c index f61a6c2b7..2ef38781d 100644 --- a/src/compiler/sema_name_resolution.c +++ b/src/compiler/sema_name_resolution.c @@ -971,6 +971,7 @@ Decl *sema_resolve_type_method(SemaContext *context, CanonicalType *type, const return NULL; } } + if (!type_may_have_method(type)) return NULL; Decl *type_decl = type->decl; if (!decl_ok(type_decl)) return poisoned_decl; Methods *methods = type_decl->method_table; diff --git a/test/test_suite/methods/method_on_non_valid_type.c3 b/test/test_suite/methods/method_on_non_valid_type.c3 new file mode 100644 index 000000000..92ad6096a --- /dev/null +++ b/test/test_suite/methods/method_on_non_valid_type.c3 @@ -0,0 +1,14 @@ +module app; + +typedef Foo = int; +fn void Foo.method(&self) +{ + self.method.anything = null; // #error: There is no member or method +} + +fn int main() +{ + Foo bar; + bar.method(); + return 0; +} \ No newline at end of file