Skip to content

Draft: Add parentof builtin

David Hewitt requested to merge davidmhewitt/vala:parentof-builtin into main

Fixes #1317

Adds a parentof builtin with that allows you to get a reference to an instance of a class or struct, from a reference or pointer to one of its public fields.

The syntax is as follows: parentof (ParentType, child_field_name, child_field_reference)

Opening as a draft to gather feedback. This is one of my first significant contributions to the compiler so please give feedback on code style, better ways to achieve the same thing, naming, things I've missed and where I should add them (docs? tests?).

I have a real-world use for this feature, as described in the linked issue report. It would make my implementation of a C library binding much less hacky and painful.

Edited by David Hewitt

Merge request reports