@@ -17,8 +17,9 @@ return function (uri, callback)
1717 --- @async
1818 guide .eachSourceType (state .ast , ' call' , function (source )
1919 await .delay ()
20- local inferred = vm .getInfer (source ):view (uri )
21- if inferred ~= ' unknown' then return end
20+
21+ local resultInfer = vm .getInfer (source ):view (uri )
22+ if resultInfer ~= ' unknown' then return end
2223 local functionType = vm .getInfer (source .node )
2324 if functionType :view (uri ) == ' unknown' then return end -- we can't say anything about what unknown types support
2425 if functionType :isCallable (uri ) then return end
@@ -28,4 +29,27 @@ return function (uri, callback)
2829 message = lang .script (' DIAG_UNKNOWN_OPERATION_CALL' , functionType :view (uri )),
2930 }
3031 end )
32+
33+ -- binary operators are quite similar to function calls, they introduce an unknown if the result is unknown and none of the
34+ -- parameters are unknown, or if the left side is known to not implement the operator
35+
36+ --- @async
37+ guide .eachSourceType (state .ast , ' binary' , function (source )
38+ await .delay ()
39+
40+ local resultInfer = vm .getInfer (source )
41+ if resultInfer :view (uri ) ~= ' unknown' then return end
42+ local left , right = source [1 ], source [2 ]
43+ local leftInfer , rightInfer = vm .getInfer (left ), vm .getInfer (right )
44+ if leftInfer :view (uri ) == ' unknown' then return end
45+ if rightInfer :view (uri ) ~= ' unknown' then
46+ -- the operator doesn't work for these types
47+ callback {
48+ start = source .start ,
49+ finish = source .finish ,
50+ message = lang .script (' DIAG_UNKNOWN_OPERATION_OPERATOR' , source .op .type , leftInfer :view (uri ), rightInfer :view (uri )),
51+ }
52+ return
53+ end
54+ end )
3155end
0 commit comments