Skip to content

Commit

Permalink
[codegen] Fix cast of static method for getter
Browse files Browse the repository at this point in the history
- when using a static method as property,
 the cast was not correct. Changed it to the same as for regular method
  • Loading branch information
parcollet committed Feb 14, 2024
1 parent f33f06c commit fb0ad90
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/plugins/c2py/codegen/classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ void codegen_getter_setter(std::ostream &code, std::ostream &table, std::ostream
// Put in the table
auto m = prop.getter.as_method();
EXPECTS(m);
auto cast_op = (m->isConst() ? "castmc<>" : "castm<>");
auto setter = (has_setter ? fmt::format("(setter)prop_set_{0}", counter) : str_t{"nullptr"});
auto cast_op = fmt::format("cast{}<>", (m ? (m->isStatic() ? "" : (m->isConst() ? "mc" : "m")) : ""));
// static method -> cast, const method -> castmc, non const, non static method -> castm

auto setter = (has_setter ? fmt::format("(setter)prop_set_{0}", counter) : str_t{"nullptr"});
table << fmt::format(R"RAW( {{"{1}", c2py::getter_from_method<c2py::{3}(&{2})>, {4}, prop_doc_{0}, nullptr}},)RAW", //
counter, prop_name, prop.getter.ptr->getQualifiedNameAsString(), cast_op, setter);

Expand Down

0 comments on commit fb0ad90

Please sign in to comment.