steep
steep copied to clipboard
Context typing with some special methods like `#freeze`
Problem
We often write code using #freeze
or #-@
.
# @type const DEFAULT_KEY: "user_id"
DEFAULT_KEY = "user_id".freeze
This doesn't work because literal type cannot be given to non-literal expressions.
Proposal
Let Steep to infer literal types on a method call when the following conditions hold:
- The method returns
self
- The receiver can have literal type
The rule No. 1 would be the key. It means that the method says the type of the return value is exactly same with the type of the receiver.
Ran into this issue with a frozen record. Took a while to figure out where the error was coming from.
Cannot be done in Steep 1.5.