@@ -133,27 +133,122 @@ end
133133function META :Copy (map --[[ #: Map<|any, any|> | nil]] , copy_tables )
134134 map = map or {}
135135
136- if map [self ] then return map [self ] end
136+ local existing = map [self ]
137+
138+ if existing then return existing end
137139
138140 local copy = META .New ()
139141 map [self ] = copy
140- copy :SetInputSignature (copy_val (self .InputSignature , map , copy_tables )--[[ # as TTuple | false]] )
141- copy :SetOutputSignature (copy_val (self .OutputSignature , map , copy_tables )--[[ # as TTuple | false]] )
142- copy :SetUpvaluePosition (self :GetUpvaluePosition ())
143- copy :SetAnalyzerFunction (self :GetAnalyzerFunction ())
144- copy :SetScope (self :GetScope ())
142+
143+ do
144+ local input = self .InputSignature
145+
146+ if input then
147+ local mapped = map [input ]
148+
149+ if mapped then
150+ copy .InputSignature = mapped
151+ else
152+ map [input ] = input :Copy (map , copy_tables )
153+ copy .InputSignature = map [input ]
154+ end
155+ else
156+ copy .InputSignature = false
157+ end
158+ end
159+
160+ do
161+ local output = self .OutputSignature
162+
163+ if output then
164+ local mapped = map [output ]
165+
166+ if mapped then
167+ copy .OutputSignature = mapped
168+ else
169+ map [output ] = output :Copy (map , copy_tables )
170+ copy .OutputSignature = map [output ]
171+ end
172+ else
173+ copy .OutputSignature = false
174+ end
175+ end
176+
177+ copy .UpvaluePosition = self .UpvaluePosition
178+ copy .AnalyzerFunction = self .AnalyzerFunction
179+ copy .Scope = self .Scope
180+ copy :CopyInternalsFrom (self )
181+ copy .FunctionBodyNode = self .FunctionBodyNode
182+ copy .InputIdentifiers = self .InputIdentifiers
183+ copy .Called = self .Called
184+ copy .ExplicitInputSignature = self .ExplicitInputSignature
185+ copy .ExplicitOutputSignature = self .ExplicitOutputSignature
186+ copy .ArgumentsInferred = self .ArgumentsInferred
187+ copy .PreventInputArgumentExpansion = self .PreventInputArgumentExpansion
188+ copy .LiteralFunction = self .LiteralFunction
189+ copy .InputArgumentsInferred = self .InputArgumentsInferred
190+ copy .InputModifiers = self .InputModifiers
191+ copy .OutputModifiers = self .OutputModifiers
192+ return copy
193+ end
194+
195+ function META :CopyForReturn (map --[[ #: Map<|any, any|> | nil]] )
196+ map = map or {}
197+
198+ local existing = map [self ]
199+
200+ if existing then return existing end
201+
202+ local copy = META .New ()
203+ map [self ] = copy
204+
205+ do
206+ local input = self .InputSignature
207+
208+ if input then
209+ local mapped = map [input ]
210+
211+ if mapped then
212+ copy .InputSignature = mapped
213+ else
214+ copy .InputSignature = input :CopyForReturn (map )
215+ end
216+ else
217+ copy .InputSignature = false
218+ end
219+ end
220+
221+ do
222+ local output = self .OutputSignature
223+
224+ if output then
225+ local mapped = map [output ]
226+
227+ if mapped then
228+ copy .OutputSignature = mapped
229+ else
230+ copy .OutputSignature = output :CopyForReturn (map )
231+ end
232+ else
233+ copy .OutputSignature = false
234+ end
235+ end
236+
237+ copy .UpvaluePosition = self .UpvaluePosition
238+ copy .AnalyzerFunction = self .AnalyzerFunction
239+ copy .Scope = self .Scope
145240 copy :CopyInternalsFrom (self )
146- copy : SetFunctionBodyNode ( self : GetFunctionBodyNode ())
147- copy : SetInputIdentifiers ( self : GetInputIdentifiers ())
148- copy : SetCalled ( self : IsCalled ())
149- copy : SetExplicitInputSignature ( self : IsExplicitInputSignature ())
150- copy : SetExplicitOutputSignature ( self : IsExplicitOutputSignature ())
151- copy : SetArgumentsInferred ( self : IsArgumentsInferred ())
152- copy : SetPreventInputArgumentExpansion ( self : GetPreventInputArgumentExpansion ())
153- copy : SetLiteralFunction ( self : IsLiteralFunction ())
154- copy : SetInputArgumentsInferred ( self : IsInputArgumentsInferred ())
155- copy : SetInputModifiers ( self .InputModifiers )
156- copy : SetOutputModifiers ( self .OutputModifiers )
241+ copy . FunctionBodyNode = self . FunctionBodyNode
242+ copy . InputIdentifiers = self . InputIdentifiers
243+ copy . Called = self . Called
244+ copy . ExplicitInputSignature = self . ExplicitInputSignature
245+ copy . ExplicitOutputSignature = self . ExplicitOutputSignature
246+ copy . ArgumentsInferred = self . ArgumentsInferred
247+ copy . PreventInputArgumentExpansion = self . PreventInputArgumentExpansion
248+ copy . LiteralFunction = self . LiteralFunction
249+ copy . InputArgumentsInferred = self . InputArgumentsInferred
250+ copy . InputModifiers = self .InputModifiers
251+ copy . OutputModifiers = self .OutputModifiers
157252 return copy
158253end
159254
0 commit comments