17859, "vasslitvinov", "Proposal to make 'Reflection.canResolve()' more general", "2021-05-29T15:27:37Z"
canResolve() family of functions in the
Reflection standard module report resolvability of a single function call. Such a call is written with the function name as an argument to
canResolve, rather than using the normal call syntax.
This issue proposes a language feature that will enable functions that report resolvability of an entire expression or of a block of code that is written using the normal syntax.
This language feature is: "possibly erroneous" closures or FCFs (first-class functions). "Possibly erroneous" means that they are allowed to contain resolution errors.
When the compiler encounters such a closure or FCF, it goes proceeds to resolving it as usual.
If resolution succeeds, the result behaves just like a normal closure or FCF: it can be passed around, evaluated, queried for its result type.
If resolution fails, no error is reported to the user. The result behaves like the
In either case, the resulting value provides a method (or perhaps a function) that indicates whether resolution succeeded.
This feature enables:
defining a flavor of
canResolvethat is a syntactic sugar for creating a possibly-erroneous closure/FSF then querying the result whether its resolution succeeded;
writing code that executes a block of code if it is resolvable and does something else otherwise.