summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/SafeFunction.h
diff options
context:
space:
mode:
authorLucas CHOLLET <lucas.chollet@free.fr>2023-01-18 18:52:14 -0500
committerAndrew Kaster <andrewdkaster@gmail.com>2023-02-04 18:47:02 -0700
commit79006c03b4aee75cfc52d8cc47c0f45068ee649e (patch)
tree01e17f6a3fbb2a076b5ed84123f8257ecb603989 /Userland/Libraries/LibJS/SafeFunction.h
parentd9f632fee7dba5b7b2293e7dfc9df6fc7a42aee3 (diff)
downloadserenity-79006c03b4aee75cfc52d8cc47c0f45068ee649e.zip
AK: Check the return type in `IsCallableWithArguments`
Template argument are checked to ensure that the `Out` type is equal or convertible to the type returned by the invokee. Compilation now fails on: `Function<void()> f = []() -> int { return 0; };` But this is allowed: `Function<ErrorOr<int>()> f = []() -> int { return 0; };`
Diffstat (limited to 'Userland/Libraries/LibJS/SafeFunction.h')
-rw-r--r--Userland/Libraries/LibJS/SafeFunction.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/SafeFunction.h b/Userland/Libraries/LibJS/SafeFunction.h
index 7a86dc95c9..0db4df7dd4 100644
--- a/Userland/Libraries/LibJS/SafeFunction.h
+++ b/Userland/Libraries/LibJS/SafeFunction.h
@@ -51,14 +51,14 @@ public:
template<typename CallableType>
SafeFunction(CallableType&& callable)
- requires((AK::IsFunctionObject<CallableType> && IsCallableWithArguments<CallableType, In...> && !IsSame<RemoveCVReference<CallableType>, SafeFunction>))
+ requires((AK::IsFunctionObject<CallableType> && IsCallableWithArguments<CallableType, Out, In...> && !IsSame<RemoveCVReference<CallableType>, SafeFunction>))
{
init_with_callable(forward<CallableType>(callable), CallableKind::FunctionObject);
}
template<typename FunctionType>
SafeFunction(FunctionType f)
- requires((AK::IsFunctionPointer<FunctionType> && IsCallableWithArguments<RemovePointer<FunctionType>, In...> && !IsSame<RemoveCVReference<FunctionType>, SafeFunction>))
+ requires((AK::IsFunctionPointer<FunctionType> && IsCallableWithArguments<RemovePointer<FunctionType>, Out, In...> && !IsSame<RemoveCVReference<FunctionType>, SafeFunction>))
{
init_with_callable(move(f), CallableKind::FunctionPointer);
}
@@ -85,7 +85,7 @@ public:
template<typename CallableType>
SafeFunction& operator=(CallableType&& callable)
- requires((AK::IsFunctionObject<CallableType> && IsCallableWithArguments<CallableType, In...>))
+ requires((AK::IsFunctionObject<CallableType> && IsCallableWithArguments<CallableType, Out, In...>))
{
clear();
init_with_callable(forward<CallableType>(callable));
@@ -94,7 +94,7 @@ public:
template<typename FunctionType>
SafeFunction& operator=(FunctionType f)
- requires((AK::IsFunctionPointer<FunctionType> && IsCallableWithArguments<RemovePointer<FunctionType>, In...>))
+ requires((AK::IsFunctionPointer<FunctionType> && IsCallableWithArguments<RemovePointer<FunctionType>, Out, In...>))
{
clear();
if (f)