Skip to content

Function Arguments Break With sol::optional<sol::table> #1727

@atom0s

Description

@atom0s

sol version: 4de99c5
Lua version: MoonJit via AshitaXI/moonjit@094d971
Compiler version: VS2022 17.13.6 (Using C++23 /std:c++latest x86)

This is also tested against x86-64 gcc (trunk) on Godbolt.

Issue Description:

There appears to be a bug with sol::optional that will break additional arguments when using multiple optionals, if one of the optionals is a sol::optional<sol::table>. When this is used, any additional following argument that is optional will no longer process properly if that given argument is nil.

For example:

auto lua_test5(
    sol::optional<sol::table> arg1,
    sol::optional<int32_t> arg2) -> void
{
    std::printf(std::format("test5: {} - {}\n", arg1.has_value() ? "Y" : "N", arg2.value_or(0)).c_str());
}

Calling this function has unexpected results, such as:

test5({}, 1234);    -- should print: Y - 1234
test5(nil, 1234);   -- should print: N - 1234
test5(nil, nil);    -- should print: N - 0

Instead, this will print:

test5: Y - 1234
test5: N - 0
test5: N - 0

Here is a Godbolt link showing the issue happening along with some additional testing to see if the issue happened with other optional usage. It seems to only trigger with tables.
https://godbolt.org/z/nY936vecK

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions