11local table = _G .table
22local NormalizeTuples = require (" nattlua.types.tuple" ).NormalizeTuples
3+ local Union = require (" nattlua.types.union" ).Union
34local Tuple = require (" nattlua.types.tuple" ).Tuple
45local Nil = require (" nattlua.types.symbol" ).Nil
56local AnalyzeImport = require (" nattlua.analyzer.expressions.import" ).AnalyzeImport
7+
8+ local function postfix_call (self , self_arg , node , callable )
9+ local types = {self_arg }
10+ self :AnalyzeExpressions (node .expressions , types )
11+
12+ local arguments
13+
14+ if self :IsTypesystem () then
15+ if
16+ # types == 1 and
17+ types [1 ].Type == " tuple" and
18+ callable :GetInputSignature ():GetTupleLength () == math.huge
19+ then
20+ arguments = types [1 ]
21+ else
22+ arguments = Tuple (types )
23+ end
24+ else
25+ arguments = NormalizeTuples (types )
26+ end
27+
28+ self :PushCurrentExpression (node )
29+ local ret , err = self :Call (callable , arguments , node )
30+ self :PopCurrentExpression ()
31+
32+ if not ret then
33+ self :Error (err )
34+
35+ if callable .Type == " function" and callable :IsExplicitOutputSignature () then
36+ return callable :GetOutputSignature ():Copy ()
37+ end
38+ end
39+
40+ return ret , err
41+ end
42+
643return {
744 AnalyzePostfixCall = function (self , node )
845 if
@@ -13,6 +50,7 @@ return {
1350 return AnalyzeImport (self , node , node .left .value .value == " require" and node .path )
1451 end
1552
53+
1654 local is_type_call = node .type_call or
1755 node .left and
1856 (
@@ -32,54 +70,44 @@ return {
3270
3371 if self :IsRuntime () then self_arg = self_arg :GetFirstValue () end
3472 end
73+ local returned_tuple
3574
36- local types = { self_arg }
37- self : AnalyzeExpressions ( node . expressions , types )
38- local arguments
75+ if self_arg and self_arg . Type == " union " then
76+ for _ , self_arg in ipairs ( self_arg : GetData ()) do
77+ local tup = postfix_call ( self , self_arg , node , callable )
3978
40- if self : IsTypesystem () then
41- if
42- # types == 1 and
43- types [ 1 ]. Type == " tuple " and
44- callable : GetInputSignature (): GetTupleLength () == math.huge
45- then
46- arguments = types [ 1 ]
47- else
48- arguments = Tuple ( types )
79+ if tup then
80+ local s = tup : GetFirstValue ()
81+ if s and not s : IsEmpty () then
82+ if returned_tuple then
83+ returned_tuple : AddType ( s )
84+ end
85+ returned_tuple = returned_tuple or Union ({ s })
86+ end
87+ end
4988 end
50- else
51- arguments = NormalizeTuples (types )
5289 end
5390
54- self :PushCurrentExpression (node )
55- local ret , err = self :Call (callable , arguments , node )
56- self :PopCurrentExpression ()
57- local returned_tuple
58-
59- if not ret then
60- self :Error (err )
61-
62- if callable .Type == " function" and callable :IsExplicitOutputSignature () then
63- returned_tuple = callable :GetOutputSignature ():Copy ()
64- else
65- returned_tuple = Tuple ({Nil ()})
91+ if not returned_tuple then
92+ local val , err = postfix_call (self , self_arg , node , callable )
93+ if not val then
94+ return val , err
6695 end
67- else
68- returned_tuple = ret
96+ returned_tuple = val
6997 end
98+ self :PopAnalyzerEnvironment ()
7099
71100 -- TUPLE UNPACK MESS
72101 if node .tokens [" (" ] and node .tokens [" )" ] and returned_tuple .Type == " tuple" then
73102 returned_tuple = returned_tuple :GetWithNumber (1 )
74103 end
75104
76105 if self :IsTypesystem () then
77- if returned_tuple .Type == " tuple" and returned_tuple :HasOneValue () then
106+ if returned_tuple and returned_tuple .Type == " tuple" and returned_tuple :HasOneValue () then
78107 returned_tuple = returned_tuple :GetWithNumber (1 )
79108 end
80109 end
81110
82- self :PopAnalyzerEnvironment ()
83111 return returned_tuple
84112 end ,
85113}
0 commit comments