mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:27:46 +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:
parent
d9f632fee7
commit
79006c03b4
4 changed files with 21 additions and 15 deletions
|
@ -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();
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue