Skip to content

Commit 5827575

Browse files
Fix partial parametric inheritance (#193)
* Add failing example of partial parametric inheritance * Fix partial parametric inheritance
1 parent 0419ca7 commit 5827575

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

examples/parametric.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ struct TemplateType
4040
}
4141
};
4242

43+
template<typename T>
44+
struct PartialTemplate : public TemplateType<P2,T>
45+
{
46+
};
47+
4348
// Template containing a non-type parameter
4449
template<typename T, T I>
4550
struct NonTypeParam
@@ -82,6 +87,14 @@ struct WrapTemplateType
8287
}
8388
};
8489

90+
struct WrapPartialTemplateType
91+
{
92+
template<typename TypeWrapperT>
93+
void operator()(TypeWrapperT&&)
94+
{
95+
}
96+
};
97+
8598
struct WrapTemplateDefaultType
8699
{
87100
template<typename TypeWrapperT>
@@ -239,6 +252,9 @@ namespace jlcxx
239252
template<typename T1> struct IsMirroredType<CppVector<T1>> : std::false_type { };
240253
template<typename T1, typename T2> struct IsMirroredType<CppVector2<T1,T2>> : std::false_type { };
241254

255+
template<typename T> struct IsMirroredType<PartialTemplate<T>> : std::false_type { };
256+
template<typename T> struct SuperType<PartialTemplate<T>> { typedef TemplateType<P2,T> type; };
257+
242258
} // namespace jlcxx
243259

244260
JLCXX_MODULE define_julia_module(jlcxx::Module& types)
@@ -249,8 +265,11 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& types)
249265
types.add_type<P1>("P1");
250266
types.add_type<P2>("P2");
251267

252-
types.add_type<Parametric<TypeVar<1>, TypeVar<2>>>("TemplateType")
253-
.apply<TemplateType<P1,P2>, TemplateType<P2,P1>>(WrapTemplateType());
268+
auto template_type = types.add_type<Parametric<TypeVar<1>, TypeVar<2>>>("TemplateType");
269+
template_type.apply<TemplateType<P1,P2>, TemplateType<P2,P1>>(WrapTemplateType());
270+
271+
types.add_type<Parametric<TypeVar<2>>, ParameterList<P2, TypeVar<2>>>("PartialTemplate", template_type.dt())
272+
.apply<PartialTemplate<P1>>(WrapPartialTemplateType());
254273

255274
types.add_type<Parametric<TypeVar<1>>>("TemplateDefaultType")
256275
.apply<TemplateDefaultType<P1>, TemplateDefaultType<P2>>(WrapTemplateDefaultType());

include/jlcxx/module.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ TypeWrapper<T> Module::add_type_internal(const std::string& name, JLSuperT* supe
13161316
fnames = jl_svec1(jl_symbol("cpp_object"));
13171317
ftypes = jl_svec1(jl_voidpointer_type);
13181318

1319-
if(jl_is_datatype(super_generic) && !jl_is_unionall(super_generic))
1319+
if(jl_is_datatype(super_generic) && !jl_is_unionall(super_generic) && !(is_parametric && SuperParametersT::nb_parameters != 0))
13201320
{
13211321
super = (jl_datatype_t*)super_generic;
13221322
}

0 commit comments

Comments
 (0)