1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:27:45 +00:00

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; };`
This commit is contained in:
Lucas CHOLLET 2023-01-18 18:52:14 -05:00 committed by Andrew Kaster
parent d9f632fee7
commit 79006c03b4
4 changed files with 21 additions and 15 deletions

View file

@ -242,7 +242,7 @@ ErrorOr<void, ParseError> Parser::expect(StringView expected)
}
template<typename Pred>
requires(IsCallableWithArguments<Pred, char>) ErrorOr<StringView, ParseError> Parser::expect(Pred predicate, StringView description)
requires(IsCallableWithArguments<Pred, bool, char>) ErrorOr<StringView, ParseError> Parser::expect(Pred predicate, StringView description)
{
auto rollback = rollback_point();
auto start = m_lexer.tell();
@ -257,7 +257,7 @@ requires(IsCallableWithArguments<Pred, char>) ErrorOr<StringView, ParseError> Pa
}
template<typename Pred>
requires(IsCallableWithArguments<Pred, char>) ErrorOr<StringView, ParseError> Parser::expect_many(Pred predicate, StringView description)
requires(IsCallableWithArguments<Pred, bool, char>) ErrorOr<StringView, ParseError> Parser::expect_many(Pred predicate, StringView description)
{
auto rollback = rollback_point();
auto start = m_lexer.tell();

View file

@ -139,9 +139,9 @@ private:
ErrorOr<void, ParseError> expect(StringView);
template<typename Pred>
requires(IsCallableWithArguments<Pred, char>) ErrorOr<StringView, ParseError> expect(Pred, StringView description);
requires(IsCallableWithArguments<Pred, bool, char>) ErrorOr<StringView, ParseError> expect(Pred, StringView description);
template<typename Pred>
requires(IsCallableWithArguments<Pred, char>) ErrorOr<StringView, ParseError> expect_many(Pred, StringView description);
requires(IsCallableWithArguments<Pred, bool, char>) ErrorOr<StringView, ParseError> expect_many(Pred, StringView description);
static size_t s_debug_indent_level;
[[nodiscard]] auto rollback_point(SourceLocation location = SourceLocation::current())