Skip to content

[python] Fix constructor of DiscreteFunction

Carsten Gräser requested to merge bugfix/remove-nonused-bindingscode into master

I was surprised to still get deprecation warnings for DefaultNodeToRangeMap from the python bindings. This is triggered by passing the result of makeDefaultNodeToRangeMap() to std::make_shared<HierarchicNodeToRangeMap>(). This cannot compile at all and is the result of a bug that I introduced this bug when changing DefaultNodeToRangeMap to HierarchicNodeToRangeMap here.

It turns out that the compiler did not complain about this obvious error, because the template was never instantiated due to SFINAE: There are two overloads of registerDiscreteFunctionConstructor(), the broken one and a completely empty one. The broken one has a template parameter TreePath. This is not passed explicitly but can also not be deduced, since the function arguments do not depend on it. Thus the empty default overload was always selected.

As a result the python class DiscreteFunction lost its constructor and could only be constructed from the C++ side. Since this is an anonymous generated type, this was never tested and thus did not trigger an error.

(Interestingly, the old version with DefaultNodeToRangeMap was also buggy, because it tried to call a non-existing constructor of the C++ class. Maybe this was also ruled out by a substitution failure that no one ever noticed due to a missing test.)

This MR fixes the bug, adds a check of the constructor, and removes the now unused include of the deprecated header.

Merge request reports

Loading