diff --git a/crates/go/src/lib.rs b/crates/go/src/lib.rs index 2c61536d3..1c290bced 100644 --- a/crates/go/src/lib.rs +++ b/crates/go/src/lib.rs @@ -2589,7 +2589,8 @@ func {camel}FromOwnHandle(handleValue int32) *{camel} {{ }} func {camel}FromBorrowHandle(handleValue int32) *{camel} {{ - return {camel}FromOwnHandle(handleValue) + handle := wit_runtime.MakeHandle(handleValue) + return &{camel}{{handle}} }} "# ); diff --git a/tests/runtime/resource-borrow/runner.go b/tests/runtime/resource-borrow/runner.go new file mode 100644 index 000000000..af0fc9766 --- /dev/null +++ b/tests/runtime/resource-borrow/runner.go @@ -0,0 +1,20 @@ +package export_wit_world + +import ( + "fmt" + test "wit_component/test_resource_borrow_to_test" +) + +func Run() { + thing := test.MakeThing(42) + defer thing.Drop() + + result := test.Foo(thing) + assertEqual(result, uint32(42+1+2)) +} + +func assertEqual[T comparable](a T, b T) { + if a != b { + panic(fmt.Sprintf("%v not equal to %v", a, b)) + } +} diff --git a/tests/runtime/resource-borrow/test.go b/tests/runtime/resource-borrow/test.go new file mode 100644 index 000000000..d03986e50 --- /dev/null +++ b/tests/runtime/resource-borrow/test.go @@ -0,0 +1,21 @@ +package export_test_resource_borrow_to_test + +import ( + "runtime" +) + +type Thing struct { + pinner runtime.Pinner + handle int32 + val uint32 +} + +func (self *Thing) OnDrop() {} + +func MakeThing(v uint32) *Thing { + return &Thing{runtime.Pinner{}, 0, v + 1} +} + +func Foo(v *Thing) uint32 { + return v.val + 2 +}