Repository navigation
codegen: always wrap register_function/add_member_function in sol::overload(...) - #315
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #314.
render_module()only wrapped a same-named group of callables insol::overload(...)when more than one real C++ overload was discovered(
len(overloads) > 1). For exactly one overload, it spliced aCodeGeneratorsubclass's ownemit_callable()return value bare intoregister_function()/add_member_function()— both single-Functemplate-parameter calls, not variadic.
emit_callable()'s own docstring already allows a subclass to returnseveral candidate lambdas for one
Callableby embedding extra top-levelcommas (the same thing
emit_constructor()has always been allowed to do,relied on by
add_constructors()'s own unconditional flat/variadicsplicing). Once a subclass legitimately needs that for a single-overload
callable — e.g. widening one reference parameter into several
sol2-exact-match candidates across a class hierarchy, since sol2's
base-class-aware usertype conversion only reliably applies to by-value
parameters, not reference ones — the bare splice above produced several
literal extra positional arguments to a function taking only one. Hard
compile error.
Fix
Always wrap in
sol::overload(...), regardless oflen(overloads). Asol::overload(...)containing exactly one function behaves identically tothe bare lambda it replaces (it's just
sol::overload_set<F>with oneF),so this is strictly more general, not a behavior change for any existing
subclass.
Deliberately not done the other way (having
emit_callable()wrap its ownmulti-candidate output in
sol::overload(...)and lettingrender_module()nest it inside another
sol::overload(...)for thelen(overloads) > 1case): confirmed directly against the vendored sol2 source
(
sol/function_types_overloaded.hpp'soverloaded_function::call) that eachcandidate needs a statically-deducible arity/signature via
function_traitsto participate in
overload_match, and a nestedoverload_sethas none.Testing
Verified against
grunk-geoml's real use case (geoml::repeat_shapewidenedfrom 1 to 9 candidates): generated code now compiles, links, and the
previously-failing recipe runs correctly end-to-end.
No existing test exercises
render_module()'s wrapping decision at thePython level directly — covered instead by every downstream plugin's own
generated-code build, which already serves as the integration test for this
code path.
Implemented with Claude