mirror of
https://github.com/ziglang/zig.git
synced 2026-02-15 05:48:31 +00:00
Sema: explain why comptime is needed
This commit is contained in:
parent
195c3cd89f
commit
76e7959a90
@ -4065,18 +4065,6 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
|
||||
var wip_captures = try WipCaptureScope.init(gpa, new_decl_arena_allocator, null);
|
||||
defer wip_captures.deinit();
|
||||
|
||||
var block_scope: Sema.Block = .{
|
||||
.parent = null,
|
||||
.sema = &sema,
|
||||
.src_decl = new_decl_index,
|
||||
.namespace = &struct_obj.namespace,
|
||||
.wip_capture_scope = wip_captures.scope,
|
||||
.instructions = .{},
|
||||
.inlining = null,
|
||||
.is_comptime = true,
|
||||
};
|
||||
defer block_scope.instructions.deinit(gpa);
|
||||
|
||||
if (sema.analyzeStructDecl(new_decl, main_struct_inst, struct_obj)) |_| {
|
||||
try wip_captures.finalize();
|
||||
new_decl.analysis = .complete;
|
||||
@ -4185,7 +4173,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
|
||||
const result_ref = (try sema.analyzeBodyBreak(&block_scope, body)).?.operand;
|
||||
try wip_captures.finalize();
|
||||
const src = LazySrcLoc.nodeOffset(0);
|
||||
const decl_tv = try sema.resolveInstValue(&block_scope, src, result_ref);
|
||||
const decl_tv = try sema.resolveInstValue(&block_scope, .unneeded, result_ref, undefined);
|
||||
const decl_align: u32 = blk: {
|
||||
const align_ref = decl.zirAlignRef();
|
||||
if (align_ref == .none) break :blk 0;
|
||||
@ -4194,7 +4182,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
|
||||
const decl_linksection: ?[*:0]const u8 = blk: {
|
||||
const linksection_ref = decl.zirLinksectionRef();
|
||||
if (linksection_ref == .none) break :blk null;
|
||||
const bytes = try sema.resolveConstString(&block_scope, src, linksection_ref);
|
||||
const bytes = try sema.resolveConstString(&block_scope, src, linksection_ref, "linksection must be comptime known");
|
||||
break :blk (try decl_arena_allocator.dupeZ(u8, bytes)).ptr;
|
||||
};
|
||||
const target = sema.mod.getTarget();
|
||||
|
||||
641
src/Sema.zig
641
src/Sema.zig
File diff suppressed because it is too large
Load Diff
@ -14,5 +14,5 @@ fn doSomeAsm() void {
|
||||
// backend=llvm
|
||||
// target=native
|
||||
//
|
||||
// :6:5: error: unable to resolve comptime value
|
||||
// :6:5: error: unable to evalutate comptime expression
|
||||
// :2:14: note: called from here
|
||||
|
||||
@ -17,4 +17,4 @@ fn bad(ok: bool) void {
|
||||
// target=native
|
||||
// backend=stage2
|
||||
//
|
||||
// :12:18: error: unable to resolve comptime value
|
||||
// :12:18: error: cannot load runtime value in comptime block
|
||||
|
||||
@ -12,4 +12,6 @@ export fn bar() void {
|
||||
// target=native
|
||||
//
|
||||
// :3:35: error: unable to resolve comptime value
|
||||
// :3:35: note: value being casted to 'comptime_int' must be comptime known
|
||||
// :7:37: error: unable to resolve comptime value
|
||||
// :7:37: note: value being casted to 'comptime_float' must be comptime known
|
||||
|
||||
@ -14,5 +14,5 @@ export fn entry() usize { return @sizeOf(@TypeOf(a)); }
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :6:26: error: unable to resolve comptime value
|
||||
// :6:26: error: cannot store to runtime value in comptime block
|
||||
// :4:17: note: called from here
|
||||
|
||||
@ -21,5 +21,5 @@ export fn function_with_return_type_type() void {
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :3:7: error: unable to resolve comptime value
|
||||
// :3:7: error: cannot load runtime value in comptime block
|
||||
// :16:19: note: called from here
|
||||
|
||||
@ -10,5 +10,5 @@ export fn entry() usize { return @offsetOf(Foo, "y"); }
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :5:25: error: unable to resolve comptime value
|
||||
// :5:25: error: cannot load runtime value in comptime block
|
||||
// :2:15: note: called from here
|
||||
|
||||
@ -6,4 +6,4 @@ extern var foo: i32;
|
||||
|
||||
// error
|
||||
//
|
||||
// :2:15: error: unable to resolve comptime value
|
||||
// :2:15: error: cannot load runtime value in comptime block
|
||||
|
||||
@ -22,3 +22,4 @@ pub fn assert(ok: bool) void {
|
||||
// error
|
||||
//
|
||||
// :3:21: error: unable to resolve comptime value
|
||||
// :3:21: note: condition in comptime branch must be comptime known
|
||||
|
||||
@ -51,8 +51,8 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
\\}
|
||||
\\var y: @import("std").builtin.CallingConvention = .C;
|
||||
, &.{
|
||||
":2:22: error: unable to resolve comptime value",
|
||||
":5:26: error: unable to resolve comptime value",
|
||||
":2:22: error: cannot load runtime value in comptime block",
|
||||
":5:26: error: cannot load runtime value in comptime block",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user