| ... | ... | @@ -9086,7 +9086,11 @@ fn finishFunc( |
| 9086 | 9086 | const tags = sema.code.instructions.items(.tag); |
| 9087 | 9087 | const data = sema.code.instructions.items(.data); |
| 9088 | 9088 | const param_body = sema.code.getParamBody(func_inst); |
| 9089 | | for (block.params.items(.is_comptime), block.params.items(.name), param_body) |is_comptime, name_nts, param_index| { |
| 9089 | for ( |
| 9090 | block.params.items(.is_comptime), |
| 9091 | block.params.items(.name), |
| 9092 | param_body[0..block.params.len], |
| 9093 | ) |is_comptime, name_nts, param_index| { |
| 9090 | 9094 | if (!is_comptime) { |
| 9091 | 9095 | const param_src = switch (tags[param_index]) { |
| 9092 | 9096 | .param => data[param_index].pl_tok.src(), |
| ... | ... | @@ -9165,6 +9169,8 @@ fn zirParam( |
| 9165 | 9169 | param_index: u32, |
| 9166 | 9170 | comptime_syntax: bool, |
| 9167 | 9171 | ) CompileError!void { |
| 9172 | const mod = sema.mod; |
| 9173 | const gpa = sema.gpa; |
| 9168 | 9174 | const inst_data = sema.code.instructions.items(.data)[inst].pl_tok; |
| 9169 | 9175 | const src = inst_data.src(); |
| 9170 | 9176 | const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index); |
| ... | ... | @@ -9260,8 +9266,28 @@ fn zirParam( |
| 9260 | 9266 | else => |e| return e, |
| 9261 | 9267 | }; |
| 9262 | 9268 | sema.inst_map.putAssumeCapacity(inst, coerced_arg); |
| 9263 | | sema.comptime_args[param_index] = (try sema.resolveConstMaybeUndefVal(block, src, coerced_arg, "parameter is declared comptime")).toIntern(); |
| 9264 | | return; |
| 9269 | if (try sema.resolveMaybeUndefVal(coerced_arg)) |val| { |
| 9270 | sema.comptime_args[param_index] = val.toIntern(); |
| 9271 | return; |
| 9272 | } |
| 9273 | const arg_src: LazySrcLoc = if (sema.generic_call_src == .node_offset) .{ .call_arg = .{ |
| 9274 | .decl = sema.generic_call_decl.unwrap().?, |
| 9275 | .call_node_offset = sema.generic_call_src.node_offset.x, |
| 9276 | .arg_index = param_index, |
| 9277 | } } else src; |
| 9278 | const msg = msg: { |
| 9279 | const src_loc = arg_src.toSrcLoc(mod.declPtr(block.src_decl), mod); |
| 9280 | const msg = try Module.ErrorMsg.create(gpa, src_loc, "{s}", .{ |
| 9281 | @as([]const u8, "runtime-known argument passed to comptime parameter"), |
| 9282 | }); |
| 9283 | errdefer msg.destroy(gpa); |
| 9284 | |
| 9285 | if (sema.generic_call_decl != .none) { |
| 9286 | try sema.errNote(block, src, msg, "{s}", .{@as([]const u8, "declared comptime here")}); |
| 9287 | } |
| 9288 | break :msg msg; |
| 9289 | }; |
| 9290 | return sema.failWithOwnedErrorMsg(msg); |
| 9265 | 9291 | } |
| 9266 | 9292 | // Even though a comptime argument is provided, the generic function wants to treat |
| 9267 | 9293 | // this as a runtime parameter. |
| ... | ... | @@ -9340,7 +9366,7 @@ fn zirParamAnytype( |
| 9340 | 9366 | errdefer msg.destroy(gpa); |
| 9341 | 9367 | |
| 9342 | 9368 | if (sema.generic_call_decl != .none) { |
| 9343 | | try sema.errNote(block, src, msg, "{s}", .{@as([]const u8, "declared here")}); |
| 9369 | try sema.errNote(block, src, msg, "{s}", .{@as([]const u8, "declared comptime here")}); |
| 9344 | 9370 | } |
| 9345 | 9371 | break :msg msg; |
| 9346 | 9372 | }; |