diff options
| author | Ian Johnson <ian@ianjohnson.dev> | 2023-04-22 20:44:57 -0400 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-04-24 09:35:54 +0300 |
| commit | 2be347a2c88e435079333773fc30b8e967cc7068 (patch) | |
| tree | 6cc383bfa7dff357fcbcb0085f76f46b070ac999 /src | |
| parent | c75e11bf6aa67f2ca62b9b6677d134592777bfec (diff) | |
| download | zig-2be347a2c88e435079333773fc30b8e967cc7068.tar.gz zig-2be347a2c88e435079333773fc30b8e967cc7068.zip | |
Sema: allow method calls on optional pointers
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 4deb2b0f29..393a05f123 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -23738,7 +23738,6 @@ fn fieldCallBind( { const first_param_type = decl_type.fnParamType(0); const first_param_tag = first_param_type.tag(); - var opt_buf: Type.Payload.ElemType = undefined; // zig fmt: off if (first_param_tag == .var_args_param or first_param_tag == .generic_poison or ( @@ -23764,17 +23763,29 @@ fn fieldCallBind( .arg0_inst = deref, }); return sema.addConstant(ty, value); - } else if (first_param_tag != .generic_poison and first_param_type.zigTypeTag() == .Optional and - first_param_type.optionalChild(&opt_buf).eql(concrete_ty, sema.mod)) - { - const deref = try sema.analyzeLoad(block, src, object_ptr, src); - const ty = Type.Tag.bound_fn.init(); - const value = try Value.Tag.bound_fn.create(arena, .{ - .func_inst = decl_val, - .arg0_inst = deref, - }); - return sema.addConstant(ty, value); - } else if (first_param_tag != .generic_poison and first_param_type.zigTypeTag() == .ErrorUnion and + } else if (first_param_type.zigTypeTag() == .Optional) { + var opt_buf: Type.Payload.ElemType = undefined; + const child = first_param_type.optionalChild(&opt_buf); + if (child.eql(concrete_ty, sema.mod)) { + const deref = try sema.analyzeLoad(block, src, object_ptr, src); + const ty = Type.Tag.bound_fn.init(); + const value = try Value.Tag.bound_fn.create(arena, .{ + .func_inst = decl_val, + .arg0_inst = deref, + }); + return sema.addConstant(ty, value); + } else if (child.zigTypeTag() == .Pointer and + child.ptrSize() == .One and + child.childType().eql(concrete_ty, sema.mod)) + { + const ty = Type.Tag.bound_fn.init(); + const value = try Value.Tag.bound_fn.create(arena, .{ + .func_inst = decl_val, + .arg0_inst = object_ptr, + }); + return sema.addConstant(ty, value); + } + } else if (first_param_type.zigTypeTag() == .ErrorUnion and first_param_type.errorUnionPayload().eql(concrete_ty, sema.mod)) { const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
