mirror of
https://github.com/ziglang/zig.git
synced 2025-12-16 03:03:09 +00:00
stage2: fix wrong value for Decl owns_tv
In the case of a comptime function call of a function that returns a type, resulting in a compiler crash on deinit().
This commit is contained in:
parent
f28868e8fd
commit
2b40815a22
@ -4037,7 +4037,6 @@ pub fn createAnonymousDeclFromDeclNamed(
|
|||||||
new_decl.ty = typed_value.ty;
|
new_decl.ty = typed_value.ty;
|
||||||
new_decl.val = typed_value.val;
|
new_decl.val = typed_value.val;
|
||||||
new_decl.has_tv = true;
|
new_decl.has_tv = true;
|
||||||
new_decl.owns_tv = true;
|
|
||||||
new_decl.analysis = .complete;
|
new_decl.analysis = .complete;
|
||||||
new_decl.generation = mod.generation;
|
new_decl.generation = mod.generation;
|
||||||
|
|
||||||
|
|||||||
@ -866,6 +866,7 @@ fn zirStructDecl(
|
|||||||
.ty = Type.initTag(.type),
|
.ty = Type.initTag(.type),
|
||||||
.val = struct_val,
|
.val = struct_val,
|
||||||
}, type_name);
|
}, type_name);
|
||||||
|
new_decl.owns_tv = true;
|
||||||
errdefer sema.mod.deleteAnonDecl(&block.base, new_decl);
|
errdefer sema.mod.deleteAnonDecl(&block.base, new_decl);
|
||||||
struct_obj.* = .{
|
struct_obj.* = .{
|
||||||
.owner_decl = new_decl,
|
.owner_decl = new_decl,
|
||||||
@ -986,6 +987,7 @@ fn zirEnumDecl(
|
|||||||
.ty = Type.initTag(.type),
|
.ty = Type.initTag(.type),
|
||||||
.val = enum_val,
|
.val = enum_val,
|
||||||
}, type_name);
|
}, type_name);
|
||||||
|
new_decl.owns_tv = true;
|
||||||
errdefer sema.mod.deleteAnonDecl(&block.base, new_decl);
|
errdefer sema.mod.deleteAnonDecl(&block.base, new_decl);
|
||||||
|
|
||||||
enum_obj.* = .{
|
enum_obj.* = .{
|
||||||
@ -1152,6 +1154,7 @@ fn zirUnionDecl(
|
|||||||
.ty = Type.initTag(.type),
|
.ty = Type.initTag(.type),
|
||||||
.val = union_val,
|
.val = union_val,
|
||||||
}, type_name);
|
}, type_name);
|
||||||
|
new_decl.owns_tv = true;
|
||||||
errdefer sema.mod.deleteAnonDecl(&block.base, new_decl);
|
errdefer sema.mod.deleteAnonDecl(&block.base, new_decl);
|
||||||
union_obj.* = .{
|
union_obj.* = .{
|
||||||
.owner_decl = new_decl,
|
.owner_decl = new_decl,
|
||||||
@ -1223,6 +1226,7 @@ fn zirErrorSetDecl(
|
|||||||
.ty = Type.initTag(.type),
|
.ty = Type.initTag(.type),
|
||||||
.val = error_set_val,
|
.val = error_set_val,
|
||||||
}, type_name);
|
}, type_name);
|
||||||
|
new_decl.owns_tv = true;
|
||||||
errdefer sema.mod.deleteAnonDecl(&block.base, new_decl);
|
errdefer sema.mod.deleteAnonDecl(&block.base, new_decl);
|
||||||
const names = try new_decl_arena.allocator.alloc([]const u8, fields.len);
|
const names = try new_decl_arena.allocator.alloc([]const u8, fields.len);
|
||||||
for (fields) |str_index, i| {
|
for (fields) |str_index, i| {
|
||||||
|
|||||||
@ -80,7 +80,7 @@ fn max_f64(a: f64, b: f64) f64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "type constructed by comptime function call" {
|
test "type constructed by comptime function call" {
|
||||||
var l: List(10) = undefined;
|
var l: SimpleList(10) = undefined;
|
||||||
l.array[0] = 10;
|
l.array[0] = 10;
|
||||||
l.array[1] = 11;
|
l.array[1] = 11;
|
||||||
l.array[2] = 12;
|
l.array[2] = 12;
|
||||||
@ -90,9 +90,30 @@ test "type constructed by comptime function call" {
|
|||||||
try expect(ptr[2] == 12);
|
try expect(ptr[2] == 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn List(comptime L: usize) type {
|
fn SimpleList(comptime L: usize) type {
|
||||||
var T = u8;
|
var T = u8;
|
||||||
return struct {
|
return struct {
|
||||||
array: [L]T,
|
array: [L]T,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "function with return type type" {
|
||||||
|
var list: List(i32) = undefined;
|
||||||
|
var list2: List(i32) = undefined;
|
||||||
|
list.length = 10;
|
||||||
|
list2.length = 10;
|
||||||
|
try expect(list.prealloc_items.len == 8);
|
||||||
|
try expect(list2.prealloc_items.len == 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn List(comptime T: type) type {
|
||||||
|
return SmallList(T, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type {
|
||||||
|
return struct {
|
||||||
|
items: []T,
|
||||||
|
length: usize,
|
||||||
|
prealloc_items: [STATIC_SIZE]T,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@ -3,27 +3,6 @@ const testing = std.testing;
|
|||||||
const expect = testing.expect;
|
const expect = testing.expect;
|
||||||
const expectEqual = testing.expectEqual;
|
const expectEqual = testing.expectEqual;
|
||||||
|
|
||||||
pub fn List(comptime T: type) type {
|
|
||||||
return SmallList(T, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type {
|
|
||||||
return struct {
|
|
||||||
items: []T,
|
|
||||||
length: usize,
|
|
||||||
prealloc_items: [STATIC_SIZE]T,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
test "function with return type type" {
|
|
||||||
var list: List(i32) = undefined;
|
|
||||||
var list2: List(i32) = undefined;
|
|
||||||
list.length = 10;
|
|
||||||
list2.length = 10;
|
|
||||||
try expect(list.prealloc_items.len == 8);
|
|
||||||
try expect(list2.prealloc_items.len == 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
test "generic struct" {
|
test "generic struct" {
|
||||||
var a1 = GenNode(i32){
|
var a1 = GenNode(i32){
|
||||||
.value = 13,
|
.value = 13,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user