Open
Description
Discussion
I believe it could be really beneficial if all stdlib public methods (ones intended to be used outside of the compiler itself and not implementation details) had parameter and return type restrictions. There are a few reasons for this:
- It helps with readability and documentation (without the example, I need to guess the type this method returns)
- It prevents accidental breaking changes like this
- It can help tooling by not having to infer the types of various methods
This can be enforced using the new Typing/*
rules that will be added in ameba 1.7.0
as part of #14608.
For certain methods such as Value#==(other)
where it can take any type, I propose we use underscores to indicate to the user that this is intended to take any type:
struct Value
# Current code
def ==(other)
false
end
# Proposed change for parameters that are intended to take any type
def ==(other : _)
false
end
end
Related: