Skip to content

Commit

Permalink
&self argument not implicitly null checked. #1556.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Oct 20, 2024
1 parent d208565 commit 9100638
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- Improve infer conversions on constants, e.g. `ZString a = foo ? "a" : "b";` #1561
- Show error when declarations do not start with `fn` in interfaces. #1565
- `if (try foo)` was handled incorrectly inside a defer.
- `&self` argument not implicitly null checked. #1556.

### Stdlib changes
- Remove unintended print of `char[]` as String
Expand Down
1 change: 1 addition & 0 deletions src/compiler/sema_decls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ static inline bool sema_analyse_signature(SemaContext *context, Signature *sig,
{
case VARDECL_PARAM_REF:
inferred_type = type_get_ptr(method_parent->type);
param->var.not_null = true;
if (!is_macro) param->var.kind = VARDECL_PARAM;
break;
case VARDECL_PARAM:
Expand Down
27 changes: 27 additions & 0 deletions test/test_suite/methods/self_methods_null.c3t
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// #target: macos-x64
// #safe: yes
module test;
distinct Foo = int;
fn void Foo.test(&self) {}
fn int main()
{
Foo* a = null;
a.test();
return 0;
}
/* #expect: test.ll

define void @test.Foo.test(ptr %0) #0 {
entry:
%1 = icmp eq ptr %0, null
%2 = call i1 @llvm.expect.i1(i1 %1, i1 false)
br i1 %2, label %panic, label %checkok

checkok: ; preds = %entry
ret void

panic: ; preds = %entry
%3 = load ptr, ptr @std.core.builtin.panic, align 8
call void %3(ptr @.panic_msg, i64 62, ptr @.file, i64 20, ptr @.func, i64 4, i32 3)
unreachable
}

0 comments on commit 9100638

Please sign in to comment.