You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Modeled C: 'returns borrow Part from param 0' on a producer-less resource generates code naming undefined type BorrowedPart #3114
A resource with no producer, declared so another resource can hand out borrows of it, generates presented code that names an undefined type. returns borrow Part from param 0 renders Option[BorrowedPart[Mime]], and the build then fails inside the generated facade with "unknown type: BorrowedPart".
If a producer-less resource isn't allowed as a borrow target, the facade clause should be refused with a diagnostic at the resource line. Generated code should never fail to resolve.
with v0.16.0.8, darwin-aarch64, c.libcurl 8.23.0 from with get.
Repro
src/facades/libcurl.w:
use c_import("curl/curl.h", link: "curl")
c facade libcurl:
resource Mime wraps *mut curl_mime
from curl_mime_init
drop curl_mime_free
resource Part wraps *mut curl_mimepart
fn curl_mime_addpart
rename add_part
returns borrow Part from param 0
(It also reports that curl_mime_init stays a raw call because its CURL *easy parameter isn't described. That's expected, and separate.)
The C contract being modeled
curl_mime_addpart(3): "Create and append a new empty part to the given mime structure and return a handle to it." Parts are owned by the mime and freed by curl_mime_free(3) ("Free all resources associated with a mime handle, including all of its parts"). So Part has no producer or destroyer of its own and only exists borrowed from its Mime, the same shape as libxml2's Node borrowed from Document (D122). Operations on it (curl_mime_name, curl_mime_data, …) would be of Part.
Expected
Either:
a producer-less resource is a valid borrow target, and the BorrowedPart type is generated along with its of Part methods; or
the facade refuses it with a diagnostic naming the right form for "a child owned by its parent". (Is that a handle with a non-callback scope?)
Merged to main ae20d89 (#3248): the facade is refused at the item, by name ("'returns borrow Part' borrows a resource that states no producer and no 'drop'"), so generated code never names an undefined type. Fixture test/compile_errors/err_3114_borrow_of_a_resource_with_no_contract.w. Whether a resource may exist only as a borrow target (curl_mimepart) is a new safe capability and goes to Eric as a brief.
Activity
Issues batch A: #1021 #1022 #1023 #2760 #3057 #3060 #3086 #3113 #3114 (…
ehartford commentedon Nov 11, 2026
Merged to main ae20d89 (#3248): the facade is refused at the item, by name ("'returns borrow Part' borrows a resource that states no producer and no 'drop'"), so generated code never names an undefined type. Fixture test/compile_errors/err_3114_borrow_of_a_resource_with_no_contract.w. Whether a resource may exist only as a borrow target (curl_mimepart) is a new safe capability and goes to Eric as a brief.