Predicate definitions with Arity above 0 should be able to end in a '?' without generating a warning to maintain consistency with simple boolean return value getters.
- Dominant language
- JavaScript
- Stars
- 6.5k
- Forks
- 183
- Avg merge
- 4h 10m
- Merged PRs (30d)
- 3
Description
### Imba Version: 2.0.0-alpha.202
### Details
In trying to define a predicate to return whether a collection contains a reference to an element, I want to end the function name with a question mark to flag its boolean result type (ie. invoke the predicate with : _collection.contains? element_)
### Expected Behavior
This should work without generating a warning unless the function definition doesn't return a boolean value. Otherwise, someone reading imba code will not be able to rely on the question mark as a marker for all predicates.
Restricting the '?' notation to getters/setters seems arbitrary and counter intuitive and would require a preceding function call to store any arguments in an element's properties or _blackboard_ construct before invoking an arity 0 getter proper. (e.g. _element.test-collecition = $list_ followed by _element.in-test-collection?_)
### Actual Behavior
The code runs but the compiler warns:
warning: [imba] Only getters/setters should end with ?
### Possible Fix
If the compiler can not infer that a boolean is being return, change the warning message to:
warning: [imba] Cannot infer a boolean return value, only functions returning true or false should end with ? If that is the case, you may safely disregard this warning.
Otherwise, permit getters to accept arguments.
Contributor guide
Assessment
This issue has not been assessed yet.