diff --git a/src/forest.cpp b/src/forest.cpp index 2de6c4932..17df68dba 100644 --- a/src/forest.cpp +++ b/src/forest.cpp @@ -76,7 +76,6 @@ Constructs a forest with *n* nodes, that is initialised so that the parents, std::vector> const& labels) { - using node_type = node_type; return make(to_ints(parents), to_ints(labels)); }), @@ -156,10 +155,7 @@ the same state as if it had just been constructed as ``Forest(n)``. "label", [](Forest const& self, node_type i) -> int_or_unsigned_constant { - if (self.label(i) != UNDEFINED) { - return {self.label(i)}; - } - return {UNDEFINED}; + return from_int(self.label(i)); }, py::arg("i"), R"pbdoc( diff --git a/src/main.hpp b/src/main.hpp index 436c73af6..a098df620 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -100,7 +100,7 @@ namespace libsemigroups { int_or_unsigned_constant>; template - Int to_int(int_or_constant val) { + Int to_int(int_or_constant const& val) { if (std::holds_alternative(val)) { return std::get<0>(val); } else if (std::holds_alternative(val)) { diff --git a/src/transf.cpp b/src/transf.cpp index 9e5126e03..3b7e1fe4c 100644 --- a/src/transf.cpp +++ b/src/transf.cpp @@ -112,6 +112,8 @@ the image of the point ``i`` under the {0} is ``imgs[i]``. // work. try { auto result = a.at(b); + // Don't use from_int here, because that will incorrectly convert + // things to LIMIT_MAX and POSITIVE_INFINITY. if (result != UNDEFINED) { return {result}; } @@ -170,6 +172,9 @@ definition, which is equal to the size of :any:`{0}.images`. [](PTransfSubclass& self) { auto r = rx::iterator_range(self.begin(), self.end()) | rx::transform( + // Don't use from_int here, because that will + // incorrectly convert things to LIMIT_MAX and + // POSITIVE_INFINITY. [](auto val) -> int_or_unsigned_constant { if (val != UNDEFINED) { return {val};