Skip to content

Conversation

@ab9rf
Copy link
Member

@ab9rf ab9rf commented May 7, 2025

some (most, actually) get methods return a pointer to a const instance of a subclass of type_identity which isn't convertible to a pointer of non-const type_identity. adding const fixes this. a pointer to non-const is always convertible to a pointer of const of the same type or of a compatible type

fixes #5450

the reason why the pointer to vector glossed as a boolean is that pointers have an implicit conversion to bool, and so when the type inference for the template failed, it fell back to the next best overload, which was the one for bool

some (most, actually) `get` methods return a pointer to a `const` instance of a subclass of `type_identity`  which isn't convertible to a pointer of non-`const` `type_identity`. adding `const` fixes this

fixes DFHack#5450
@lethosor
Copy link
Member

lethosor commented May 7, 2025

Is this something we could catch in a unit test? I guess it would require a C++ function that takes an affected type...

@ab9rf
Copy link
Member Author

ab9rf commented May 7, 2025

Is this something we could catch in a unit test? I guess it would require a C++ function that takes an affected type...

I should probably add some static_asserts, since that's basically how I found it (along with single stepping).

This particular one is insuring that Lua::Push(lua_State,bool) doesn't get "grabby", since that overload will capture any type that has an implicit conversion to bool (and lots of things have implicit conversions to bool) and doesn't get matched
without a conversion chain.

More generally, I would like to see some C++ unit testing but we don't currently have a good framework for that. Suggestions welcome.

@myk002
Copy link
Member

myk002 commented May 8, 2025

C++ unit testing

We do have cpp unit tests set up. There's an example unit test for miscutils

https://github.com/DFHack/dfhack/blob/develop/library/MiscUtils.test.cpp

@myk002 myk002 merged commit 6947f6f into DFHack:develop May 8, 2025
13 of 14 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.

Bug: Vector passed to Lua as bool

3 participants