Better type hinting for binary conditional expressions
The type hinting currently relies on left
or right
types being defined, which would only happen from things during pre-type checking. Due to this, only things such as local variables will actually help. This isn't a huge issue since ideally there wouldn't be many name ambiguities in peoples projects, but it is definitely possible.
A possible solution to this is to visit specific expression node types before defining the type hints. Doing so would allow things like proc
calls to specify the return type from the symbol type.
Example of what would happen currently with the current system.
Symbols:
type | name |
---|---|
stat | hitpoints |
npc_stat | hitpoints |
Code:
[proc,demo](int $stat_id)
// hitpoints would resolve to the stat version instead of npc_stat, causing an error of npc_stat != stat.
// this could be solved by knowing that the lhs can be visited to get the type, then type hint the right side.
if (~get_npc_stat($stat_id) = hitpoints) {
}
[proc,get_npc_stat](int $type)(npc_stat)
return(...);