Skip to content

Conversation

@halleysfifthinc
Copy link
Contributor

@halleysfifthinc halleysfifthinc commented Nov 7, 2025

https://github.com/halleysfifthinc/CxxWrap.jl/#test-partial-param-inherit

Parametric inheritance from parametric types with some fixed parameters is not currently accurately reflected on the Julia side.

For example, the expected Julia wrapped supertype of this C++ type

template<typename T>
struct PartialTemplate : public TemplateType<P2,T> {};

should look like PartialTemplate{T} <: TemplateType{P2,T}.

I have a test PR ready for the CxxWrap.jl side, but it will obviously fail until this PR goes through; I'm not sure if you have a way of handling that besides running the tests manually?

@barche
Copy link
Contributor

barche commented Nov 11, 2025

Thanks for the PR. I did some experimenting, and there is an error on finalization of types that are created this way (both with and without your fix). To test with an adapted CxxWrap.jl you can add a link to the testing branch in the first line of the PR, as done e.g. here: #190

@barche
Copy link
Contributor

barche commented Nov 12, 2025

Can you in the test in CxxWrap.jl create some instances of PartialTemplate? This should show the problem I saw locally upon finalization. It seems the __delete method gets a type of PartialTemplateAllocated{...} instead of PartialTemplate{...}. You can see this using methods(CxxWrap.CxxWrapCore.__delete. No idea why as of yet :)

@halleysfifthinc
Copy link
Contributor Author

I think @test (finalize(ParametricTypes.PartialTemplate{ParametricTypes.P1}()); true) would test on the Julia side that this issue was fixed/avoided.

However, I'm not sure that would be a good test of the actual problem, which was programmer/wrapping error (I hadn't defined the SuperType template in the C++ side). With that template, I'm only seeing the __delete methods I would expect:

julia> methodswith(CxxPtr{<:ParametricTypes.PartialTemplate{ParametricTypes.P1}}, CxxWrap.CxxWrapCore.__delete; supertypes=true)
[1] __delete(arg1::Union{Ptr{Nothing}, CxxPtr{<:Main.ParametricTypes.PartialTemplate{Main.ParametricTypes.P1}}}) @ Main.ParametricTypes ~/Dropbox/documents/technology/development/julia-dev/CxxWrap/src/CxxWrap.jl:715
[2] __delete(arg1::Union{Ptr{Nothing}, CxxPtr{<:Main.ParametricTypes.TemplateType{Main.ParametricTypes.P2, Main.ParametricTypes.P1}}}) @ Main.ParametricTypes ~/Dropbox/documents/technology/development/julia-dev/CxxWrap/src/CxxWrap.jl:715

I think a better/more user friendly solution would be a check (ideally compile-time; probably in the create_internal_type function?) to require that !std::is_same<supertype<T>, T>::value? Ultimately the goal would be to catch the inconsistent programmer input of A) explicitly provided supertype in the add_type function, and B) no matching SuperType template.

@barche
Copy link
Contributor

barche commented Nov 14, 2025

I would suggest the following test on the Julia side:

let partial = PartialTemplate{ParametricTypes.P1}()
    @test convert(TemplateType{ParametricTypes.P2,ParametricTypes.P1}, partial).cpp_object == partial.cpp_object
end

It's a good idea to test at compile time for the proper SuperType. I think that can be a separate PR however, so for me this one can be merged.

@barche barche merged commit 5827575 into JuliaInterop:main Nov 14, 2025
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants