Skip to content

Modeled C: 'returns borrow Part from param 0' on a producer-less resource generates code naming undefined type BorrowedPart #3114

Closed

Description

@ehartford

Summary

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

src/main.w:

use facades.libcurl

fn main:
    print("ok")
error: unknown type: BorrowedPart
 --> <facade libcurl>:6:33
6 |     pub fn add_part() -> Option[BorrowedPart[Mime]]:
  |                                 ^^^^^^^^^^^^^^^^^^

(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?)

Context: #3111 (gap 5).

Activity

  1. added
    bug
    on Nov 9, 2026
  2. ehartford commented on Nov 11, 2026

    @ehartford
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions