Skip to content

hy-emit: resolve foreign MethodZero accessors and nested struct shapes on place targets - #2137

Open
comandanto wants to merge 1 commit into
limitlessprojects:mainfrom
comandanto:fix/place-receiver-foreign-methodzero-nested-2128
Open

comandanto wants to merge 1 commit into
limitlessprojects:mainfrom
comandanto:fix/place-receiver-foreign-methodzero-nested-2128

Conversation

@comandanto

Copy link
Copy Markdown

Summary

In compiler/crates/hy-emit/src/stmt.rs, place_member_name previously only checked whether the assignment target root is a foreign package or binding (self.is_unshadowed_pkg_root(root) / self.bindings.get(root)). Consequently, it did not consult SHAPES (lookup_member), var_ty, or nested struct field shapes (var_struct + struct_fields).

This caused two buildable lowering bugs:

  1. Indexing a zero-arg foreign accessor method on the LHS of an assignment (w.header["X-Mode"] = ...) emitted w.Header[...] without parentheses instead of calling the accessor w.Header()[...], failing go build with cannot index w.Header (value of type func() http.Header).
  2. Assigning to a foreign field nested within user structs (c.req.host = ... on struct req_ctx { req *http.request }) emitted lowercase c.req.host because the root variable c is a user struct, failing go build with type *http.Request has no field or method host, but does have field Host.

Proposed Changes

  • Added Emitter::struct_type_of_place and Emitter::type_of_place in compiler/crates/hy-emit/src/stmt.rs mirroring the expression-side typing logic.
  • Updated place_member_name to look up member metadata for self.type_of_place(base). When MemberKind::MethodZero is returned, () is appended (w.Header()). When MemberKind::Field is returned, the Go field name is emitted (Host).

Verification

  • Added regression tests in compiler/crates/hy-emit/tests/place_receiver_shapes_issue_2128.rs covering:
    • Zero-arg method accessor indexing: w.header["X-Mode"] = []string{"fast"} -> w.Header()["X-Mode"] = []string{"fast"}.
    • Foreign field nested in user struct and outer struct: c.req.host = ... -> c.req.Host = ..., o.inner.req.host = ... -> o.inner.req.Host = ....
  • Ran all existing hy-emit unit and integration tests (188+ tests pass).
  • Ran python tools/check_test_registration.py (32 test files, 29 patterns: OK).
  • Ran python tools/check_conflict_markers.py --root . (clean).

Closes #2128

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

Labels

bot:land-candidate Shepherd: fresh, gate-clean, verifiable (set from classify())

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[buildable] hy-emit: assignment target Place receiver misses foreign MethodZero () and nested struct foreign shapes

1 participant