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

Improve compile error for incorrect function passed in observe, modify etc #96

Open
YarikTH opened this issue Aug 29, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@YarikTH
Copy link
Owner

YarikTH commented Aug 29, 2021

Description

I made a mistake with passing 2 args lambda to observe a single signal.

int main()
{
    ureact::context ctx;
    
    ureact::value<int> a = make_value( ctx, 1 );
    ureact::value<int> b = make_value( ctx, 1 );

    auto obs = ureact::observe( a + b, []( int a, int b ){} );
}

I received the following error message:

In file included from D:/mingw32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/bits/move.h:54:0,
                 from D:/mingw32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/bits/nested_exception.h:40,
                 from D:/mingw32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/exception:143,
                 from D:/mingw32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/ios:39,
                 from D:/mingw32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/ostream:38,
                 from D:/mingw32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/iostream:39,
                 from D:\Workspace\ureact\tests\src\playground\main.cpp:8:
D:/mingw32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/type_traits: In substitution of 'template<class _Fn, class ... _Args> using invoke_result_t = typename std::invoke_result::type [with _Fn = main()::<lambda(int, int)>; _Args = {int}]':
D:/Workspace/ureact/include/ureact/ureact.hpp:2284:44:   required from 'ureact::v0::observer ureact::v0::detail::observe_impl(const ureact::v0::signal<R>&, in_f&&) [with in_f = main()::<lambda(int, int)>; S = int]'
D:/Workspace/ureact/include/ureact/ureact.hpp:2326:42:   required from 'ureact::v0::observer ureact::v0::observe(ureact::v0::signal<R>&&, in_f&&) [with in_f = main()::<lambda(int, int)>; S = int]'
D:\Workspace\ureact\tests\src\playground\main.cpp:22:61:   required from here
D:/mingw32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/type_traits:2836:72: error: no type named 'type' in 'struct std::invoke_result<main()::<lambda(int, int)>, int>'
     using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
                                                                        ^
In file included from D:\Workspace\ureact\tests\src\playground\main.cpp:10:0:
D:/Workspace/ureact/include/ureact/ureact.hpp: In instantiation of 'ureact::v0::observer ureact::v0::detail::observe_impl(const ureact::v0::signal<R>&, in_f&&) [with in_f = main()::<lambda(int, int)>; S = int]':
D:/Workspace/ureact/include/ureact/ureact.hpp:2326:42:   required from 'ureact::v0::observer ureact::v0::observe(ureact::v0::signal<R>&&, in_f&&) [with in_f = main()::<lambda(int, int)>; S = int]'
D:\Workspace\ureact\tests\src\playground\main.cpp:22:61:   required from here
D:/Workspace/ureact/include/ureact/ureact.hpp:2289:39: error: no type named 'type' in 'struct std::invoke_result<main()::<lambda(int, int)>, int>'
     using node_t = std::conditional_t<std::is_same_v<void, R>,
                                       ^~~

It seems that I need a proper compile-time diagnostic to blame the user for incorrect usage, and give him a hint to fix it.
std::is_invocable to the resque.

@YarikTH YarikTH added the enhancement New feature or request label Aug 29, 2021
@YarikTH YarikTH added this to the 0.5.0 milestone Aug 29, 2021
@YarikTH YarikTH self-assigned this Aug 29, 2021
@YarikTH YarikTH removed this from the 0.5.0 milestone Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant