Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result<T, E>::and_then not working as expected #458

Open
cjdb opened this issue Sep 16, 2024 · 1 comment
Open

Result<T, E>::and_then not working as expected #458

cjdb opened this issue Sep 16, 2024 · 1 comment

Comments

@cjdb
Copy link

cjdb commented Sep 16, 2024

The following code works when using std::expected, but errors with sus::Result.

static auto set_attrib_pointer(vertex_array array) -> sus::Result<vertex_array, error>
{
	if constexpr (is_coloured_position<T>) {
		return set_attrib_pointer<decltype(T::position)>(std::move(array), 0, 0).and_then(test);
	}
	else {
		return set_attrib_pointer(array, 0, 0);
	}
}

template<class U>
static auto set_attrib_pointer(vertex_array array, GLuint const location_offset, GLuint const offset_by) -> sus::Result<vertex_array, error>;
FAILED: source/shaders/CMakeFiles/shaders.dir/shaders.cpp.o 
/home/cjdb/opt/bin/clang++ --target=x86_64-unknown-linux-gnu  -isystem /home/cjdb/projects/learnopengl/build/vcpkg_installed/vcpkg_toolchain_file/include -isystem /home/cjdb/projects/learnopengl/build/vcpkg_installed/vcpkg_toolchain_file/include/sus -fdiagnostics-color=always -fstack-protector-strong -fvisibility=hidden -fno-rtti -Werror -pedantic -Wall -Wattributes -Wcast-align -Wconversion -Wdouble-promotion -Wextra -Wformat=2 -Wnon-virtual-dtor -Wnull-dereference -Wodr -Wold-style-cast -Woverloaded-virtual -Wshadow -Wsign-conversion -Wsign-promo -Wunused -Wno-ignored-attributes -Wno-unused-command-line-argument -stdlib=libc++ -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST -fsanitize=address -g -std=gnu++23 -fno-rtti -Wno-nullability-completeness -MD -MT source/shaders/CMakeFiles/shaders.dir/shaders.cpp.o -MF source/shaders/CMakeFiles/shaders.dir/shaders.cpp.o.d @source/shaders/CMakeFiles/shaders.dir/shaders.cpp.o.modmap -o source/shaders/CMakeFiles/shaders.dir/shaders.cpp.o -c /home/cjdb/projects/learnopengl/source/shaders/shaders.cpp
In file included from /home/cjdb/projects/learnopengl/source/shaders/shaders.cpp:9:
/home/cjdb/projects/learnopengl/build/vcpkg_installed/vcpkg_toolchain_file/include/sus/result/result.h:430:23: error: constraints not satisfied for alias template 'ReturnOnce' [with F = (lambda at /home/cjdb/projects/learnopengl/source/lib/buffers.cpp:235:87), Args = <>]
  430 |       return sus::fn::ReturnOnce<AndFn>::with_err(storage_.take_err());
      |                       ^~~~~~~~~~~~~~~~~
/home/cjdb/projects/learnopengl/source/lib/buffers.cpp:235:78: note: in instantiation of function template specialization 'sus::result::Result<buffers::vertex_array<buffers::buffer_type::array, buffers::coloured_position<3>>, buffers::error>::and_then<(lambda at /home/cjdb/projects/learnopengl/source/lib/buffers.cpp:235:87)>' requested here
  235 |                                 return set_attrib_pointer<decltype(T::position)>(std::move(array), 0, 0).and_then([](vertex_array array) {
      |                                                                                                          ^
/home/cjdb/projects/learnopengl/source/lib/buffers.cpp:186:11: note: in instantiation of member function 'buffers::vertex_array<buffers::buffer_type::array, buffers::coloured_position<3>>::set_attrib_pointer' requested here
  186 |                         return set_attrib_pointer(vertex_array{id, b});
      |                                ^
/home/cjdb/projects/learnopengl/source/shaders/shaders.cpp:97:71: note: in instantiation of member function 'buffers::vertex_array<buffers::buffer_type::array, buffers::coloured_position<3>>::make' requested here
   97 |         auto access = buffers::array_accessor<buffers::coloured_position3d>::make(points).unwrap_or_else(
      |                                                                              ^
/home/cjdb/projects/learnopengl/build/vcpkg_installed/vcpkg_toolchain_file/include/sus/fn/fn_concepts.h:469:12: note: because 'FnOnce<(lambda at /home/cjdb/projects/learnopengl/source/lib/buffers.cpp:235:87), Anything ()>' evaluated to false
  469 |   requires(FnOnce<F, Anything(Args...)>)
      |            ^
/home/cjdb/projects/learnopengl/build/vcpkg_installed/vcpkg_toolchain_file/include/sus/fn/fn_concepts.h:173:8: note: because type constraint '__private::ValidReturnType<sus::fn::__private::NoOverloadMatchesArguments, typename __private::Sig<Anything ()>::Return>' was not satisfied:
  173 |   } -> __private::ValidReturnType<typename __private::Sig<S...>::Return>;
      |        ^
/home/cjdb/projects/learnopengl/build/vcpkg_installed/vcpkg_toolchain_file/include/sus/fn/__private/signature.h:126:5: note: because '!std::same_as<sus::fn::__private::NoOverloadMatchesArguments, NoOverloadMatchesArguments>' evaluated to false
  126 |     !std::same_as<ReturnType, NoOverloadMatchesArguments> &&
      |     ^
1 error generated.

I don't see any tests for Result::and_then; should I switch back to std::expected for the time being?

@danakj
Copy link
Collaborator

danakj commented Sep 16, 2024

What's the type of test?

In case it's not clear, the !std::same_as<ReturnType, NoOverloadMatchesArguments> is saying what the text says, that the arguments are not binding to a callable signature. Maybe it's not testing convertible somewhere.

Result is not as 100%'d as Option is: #185 is the bug for completing the API to match https://doc.rust-lang.org/stable/std/result/enum.Result.html and provide tests for everything. It was enough for me to make use of it in Subdoc and the rest of the sus library so far, basically.

If you're up for fixing it, I'd be happy to review it, or I can try get to fixing this. I don't like leaving something broken in here.

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

No branches or pull requests

2 participants