@@ -370,7 +370,32 @@ return function(self, obj, input)
370370 function_node .Type == " statement_type_function"
371371 then
372372 if function_node .self_call then
373- self :CreateLocalValue (" self" , input :GetWithNumber (1 ) or Nil ())
373+ local arg = input :GetWithNumber (1 ) or Nil ()
374+ self :CreateLocalValue (" self" , arg )
375+
376+ -- if the meta table has @SelfArgument, also create a typesystem self
377+ -- so that --[[#type]] blocks see the contract type instead of the concrete value
378+ if not is_type_function and arg .Type == " table" then
379+ local self_arg_contract
380+
381+ if arg :GetSelfArgument () then
382+ self_arg_contract = arg :GetSelfArgument ()
383+ elseif arg :GetMetaTable () and arg :GetMetaTable ().Type == " table" then
384+ self_arg_contract = arg :GetMetaTable ():GetSelfArgument ()
385+ end
386+
387+ if self_arg_contract then
388+ -- make @SelfArgument accessible from the contract itself
389+ -- so that self.@SelfArgument works in typesystem blocks
390+ if not self_arg_contract :GetSelfArgument () then
391+ self_arg_contract :SetSelfArgument (self_arg_contract )
392+ end
393+
394+ self :PushAnalyzerEnvironment (" typesystem" )
395+ self :CreateLocalValue (" self" , self_arg_contract )
396+ self :PopAnalyzerEnvironment ()
397+ end
398+ end
374399 end
375400 end
376401
@@ -385,12 +410,9 @@ return function(self, obj, input)
385410 for i , identifier in ipairs (function_node .identifiers_typesystem ) do
386411 local generic_expression = call_expression .expressions_typesystem and
387412 call_expression .expressions_typesystem [i ] or
388- nil
389-
390- if generic_expression then
391- local T = self :AnalyzeExpression (generic_expression )
392- self :CreateLocalValue (identifier .value :GetValueString (), T )
393- end
413+ identifier
414+ local T = self :AnalyzeExpression (generic_expression )
415+ self :CreateLocalValue (identifier .value :GetValueString (), T )
394416 end
395417 end
396418
0 commit comments