Skip to content

Commit

Permalink
Update uses of @fieldParentPtr to use RLS
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobly0 committed Mar 31, 2024
1 parent 548ca31 commit d0275a9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions compile_errors/fieldParentPtr-bad_field_name.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const Foo = extern struct {
derp: i32,
};
export fn foo(a: *i32) *Foo {
return @fieldParentPtr(*Foo, "a", a);
return @fieldParentPtr("a", a);
}

// error
// backend=stage2
// target=native
//
// :5:34: error: no field named 'a' in struct 'tmp.Foo'
// :5:28: error: no field named 'a' in struct 'tmp.Foo'
// :1:20: note: struct declared here
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const foo = Foo{

comptime {
const field_ptr: *i32 = @ptrFromInt(0x1234);
const another_foo_ptr = @fieldParentPtr(*const Foo, "b", field_ptr);
const another_foo_ptr: *const Foo = @fieldParentPtr("b", field_ptr);
_ = another_foo_ptr;
}

Expand Down
4 changes: 2 additions & 2 deletions compile_errors/fieldParentPtr-comptime_wrong_field_index.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const foo = Foo{
};

comptime {
const another_foo_ptr = @fieldParentPtr(*const Foo, "b", &foo.a);
const another_foo_ptr: *const Foo = @fieldParentPtr("b", &foo.a);
_ = another_foo_ptr;
}

// error
// backend=stage2
// target=native
//
// :11:29: error: field 'b' has index '1' but pointer value is index '0' of struct 'tmp.Foo'
// :11:41: error: field 'b' has index '1' but pointer value is index '0' of struct 'tmp.Foo'
// :1:13: note: struct declared here
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const Foo = extern struct {
a: i32,
};
export fn foo(a: i32) *Foo {
return @fieldParentPtr(*const Foo, "a", a);
export fn foo(a: i32) *const Foo {
return @fieldParentPtr("a", a);
}

// error
// backend=stage2
// target=native
//
// :5:45: error: expected pointer type, found 'i32'
// :5:33: error: expected pointer type, found 'i32'
6 changes: 3 additions & 3 deletions compile_errors/fieldParentPtr-non_pointer.zig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const Foo = i32;
export fn foo(a: *i32) *Foo {
return @fieldParentPtr(Foo, "a", a);
export fn foo(a: *i32) Foo {
return @fieldParentPtr("a", a);
}

// error
// backend=llvm
// target=native
//
// :3:28: error: expected pointer type, found 'i32'
// :3:12: error: expected pointer type, found 'i32'
4 changes: 2 additions & 2 deletions compile_errors/fieldParentPtr_on_comptime_field.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ pub export fn entry1() void {
@offsetOf(T, "a");
}
pub export fn entry2() void {
@fieldParentPtr(*T, "a", undefined);
@as(*T, @fieldParentPtr("a", undefined));
}

// error
// backend=stage2
// target=native
//
// :5:5: error: no offset available for comptime field
// :8:25: error: cannot get @fieldParentPtr of a comptime field
// :8:29: error: cannot get @fieldParentPtr of a comptime field

0 comments on commit d0275a9

Please sign in to comment.