@@ -503,66 +503,7 @@ analyzer function setmetatable(tbl: Table, meta: Table | nil)
503503 end
504504
505505 if meta.Type == "table" then
506- if meta.NewMetaTable and not meta.Self then
507- -- @NewMetaTable mode: build an inferred Self from tbl's fields
508- -- This is informational (no contract enforcement)
509- local inferred_self = types.Table()
510- for _, kv in ipairs(tbl:GetData()) do
511- local key = kv.key
512- local val = kv.val
513- -- Widen literal values to their base types for the inferred self
514- if val:IsLiteral() and val.Type ~= "function" and val.Type ~= "table" and val.Widen then
515- val = val:Widen()
516- end
517- inferred_self:Set(key, val)
518- end
519- inferred_self:SetMetaTable(meta)
520- meta.Self = inferred_self
521- elseif meta.NewMetaTable and meta.Self then
522- -- Subsequent setmetatable calls: merge additional fields
523- for _, kv in ipairs(tbl:GetData()) do
524- local key = kv.key
525- local val = kv.val
526- if val:IsLiteral() and val.Type ~= "function" and val.Type ~= "table" and val.Widen then
527- val = val:Widen()
528- end
529- if not meta.Self:HasKey(key) then
530- meta.Self:Set(key, val)
531- end
532- end
533- elseif meta.Self then
534- analyzer:ErrorIfFalse(tbl:FollowsContract(meta.Self))
535- tbl:CopyLiteralness2(meta.Self)
536- tbl:SetContract(meta.Self)
537- -- clear mutations so that when looking up values in the table they won't return their initial value
538- tbl:ClearMutations()
539- elseif analyzer:IsRuntime() then
540- meta.potential_self = meta.potential_self or types.Union()
541- meta.potential_self:AddType(tbl)
542- end
543-
544506 tbl:SetMetaTable(meta)
545-
546- if analyzer:IsTypesystem() then return tbl end
547-
548- local metatable_functions = analyzer:CallTypesystemUpvalue(types.ConstString("MetaTableFunctions"), tbl)
549-
550- for _, kv in ipairs(metatable_functions:GetData()) do
551- local a = kv.val
552- local b = meta:Get(kv.key)
553-
554- if b and b.Type == "function" then
555- local ok = a:IsSubsetOf(b)
556-
557- if ok then
558-
559- --TODO: enrich callback types
560- --b:SetOutputSignature(a:GetOutputSignature())
561- --b:SetInputSignature(a:GetInputSignature())
562- --b.arguments_inferred = true
563- end
564- end
565- end
566507 end
567508
568509 return tbl
0 commit comments