Skip to content

Commit 4e68649

Browse files
committed
[Diagnostics] Add an educational note about @dynamicCallable requirements
1 parent 667fc05 commit 4e68649

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/swift/AST/EducationalNotes.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ EDUCATIONAL_NOTES(associated_type_witness_conform_impossible,
2929
EDUCATIONAL_NOTES(cannot_infer_closure_result_type,
3030
"complex-closure-inference.md")
3131

32+
EDUCATIONAL_NOTES(invalid_dynamic_callable_type,
33+
"dynamic-callable-requirements.md")
34+
EDUCATIONAL_NOTES(missing_dynamic_callable_kwargs_method,
35+
"dynamic-callable-requirements.md")
36+
3237
#undef EDUCATIONAL_NOTES
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@dynamicCallable Implementation Requirements
2+
---
3+
If a type is marked with the `@dynamicCallable` attribute, it must provide a valid implementation of `dynamicallyCall(withArguments:)`, `dynamicallyCall(withKeywordArguments:)`, or both. If it fails to do so, an error will be reported at compile-time. Note that an implementation of `dynamicallyCall(withKeywordArguments:)` is required to support calls with keyword arguments.
4+
5+
To be considered valid, an implementation of `dynamicallyCall(withArguments:)` must:
6+
- Be an instance method. `static` or `class` implementations are not allowed.
7+
- Have an argument type which conforms to the `ExpressibleByArrayLiteral` protocol. Often, this will be the built in `Array` type.
8+
- The return type of `dynamicallyCall(withArguments:)` may be any valid type.
9+
10+
To be considered valid, an implementation of `dynamicallyCall(withKeywordArguments:)` must:
11+
- Be an instance method. `static` or `class` implementations are not allowed.
12+
- Have an argument type which conforms to the `ExpressibleByDictionaryLiteral` protocol. This can be `Dictionary`, `KeyValuePairs` (which may be used to support duplicated keyword arguments), or some other conforming type.
13+
- The `Key` associated type of the argument type must conform to the `ExpressibleByStringLiteral` protocol. This type is used to represent the dynamic argument keywords.
14+
- The `Value` associated type of the argument type and the return type of `dynamicallyCall(withKeywordArguments:)` may be any valid types.

0 commit comments

Comments
 (0)