@@ -32,6 +32,44 @@ local function restore_mutated_types(self)
3232 table_clear (env .mutated_types )
3333end
3434
35+ local function can_wrap_table_argument (contract )
36+ if contract .Type == " table" then return true end
37+
38+ if contract .Type ~= " union" then return false end
39+
40+ for _ , obj in ipairs (contract :GetData ()) do
41+ if obj .Type ~= " table" and (obj .Type ~= " symbol" or not obj :IsNil ()) then
42+ return false
43+ end
44+ end
45+
46+ return true
47+ end
48+
49+ local function get_argument_value (arg , contract )
50+ if
51+ arg and
52+ arg .Type == " table" and
53+ can_wrap_table_argument (contract ) and
54+ not arg :GetMetaTable ()
55+ and
56+ not arg :GetTypeOverride ()
57+ and
58+ not arg :GetName ()
59+ and
60+ not arg :IsUnique ()
61+ then
62+ local tbl = Table ()
63+ tbl :SetContract (contract )
64+ tbl :SetAnalyzerEnvironment (arg :GetAnalyzerEnvironment ())
65+ return tbl
66+ end
67+
68+ local val = contract :GetFirstValue ():Copy (nil , true )
69+ val :SetContract (contract )
70+ return val
71+ end
72+
3573local function shrink_union_to_function_signature (obj )
3674 local arg = Tuple ()
3775 local ret = Tuple ()
@@ -314,9 +352,7 @@ return function(self, obj, input)
314352 test<|number|>(1)
315353 ]]
316354 -- if it's a ref argument we pass the incoming value
317- local t = contract :GetFirstValue ():Copy (nil , true )
318- t :SetContract (contract )
319- input :Set (i , t )
355+ input :Set (i , get_argument_value (arg , contract ))
320356 end
321357 elseif
322358 arg and
@@ -337,15 +373,11 @@ return function(self, obj, input)
337373
338374 if doit then
339375 -- if it's not a ref argument we pass the incoming value
340- local t = contract :GetFirstValue ():Copy (nil , true )
341- t :SetContract (contract )
342- input :Set (i , t )
376+ input :Set (i , get_argument_value (arg , contract ))
343377 end
344378 else
345379 if arg .Type == " any" and arg .Type ~= contract .Type then
346- local t = contract :GetFirstValue ():Copy (nil , true )
347- t :SetContract (contract )
348- input :Set (i , t )
380+ input :Set (i , get_argument_value (arg , contract ))
349381 end
350382 end
351383 end
0 commit comments