From 2eb09c1a9b7bb5bd066eba5b74f095684d7464b3 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 8 Aug 2024 11:46:31 -0300 Subject: [PATCH] self: remove magic behavior for nominal "@self" --- tl.lua | 17 +++-------------- tl.tl | 17 +++-------------- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/tl.lua b/tl.lua index 7217bffa..10b21718 100644 --- a/tl.lua +++ b/tl.lua @@ -3785,7 +3785,7 @@ do typ.is_method = true typ.min_arity = 1 typ.args = new_tuple(ps, wstart, { - a_nominal(where_macroexp, { "@self" }), + a_type(where_macroexp, "self", {}), }) typ.rets = new_tuple(ps, wstart, { new_type(ps, wstart, "boolean") }) typ.macroexp = where_macroexp @@ -6557,10 +6557,6 @@ local function show_type_base(t, short, seen) end if t.typename == "nominal" then - if #t.names == 1 and t.names[1] == "@self" then - return "self" - end - local ret if t.typevals then local out = { table.concat(t.names, "."), "<" } @@ -8033,19 +8029,11 @@ do return arr_type end - local function is_self(t) - return t.typename == "self" or (t.typename == "nominal" and t.names[1] == "@self") - end - local function compare_true(_, _, _) return true end function TypeChecker:subtype_nominal(a, b) - if is_self(a) and is_self(b) then - return true - end - local ra = a.typename == "nominal" and self:resolve_nominal(a) or a local rb = b.typename == "nominal" and self:resolve_nominal(b) or b local ok, errs = self:is_a(ra, rb) @@ -9076,7 +9064,8 @@ a.types[i], b.types[i]), } if argdelta == -1 then from = 2 local errs = {} - if (not is_self(fargs[1])) and not self:arg_check(w, errs, fargs[1], args.tuple[1], "contravariant", "self") then + local first = fargs[1] + if (not (first.typename == "self")) and not self:arg_check(w, errs, first, args.tuple[1], "contravariant", "self") then return nil, errs end end diff --git a/tl.tl b/tl.tl index 551c3439..525a9ca6 100644 --- a/tl.tl +++ b/tl.tl @@ -3785,7 +3785,7 @@ parse_record_body = function(ps: ParseState, i: integer, def: RecordLikeType, no typ.is_method = true typ.min_arity = 1 typ.args = new_tuple(ps, wstart, { - a_nominal(where_macroexp, { "@self" }) + a_type(where_macroexp, "self", {}) }) typ.rets = new_tuple(ps, wstart, { new_type(ps, wstart, "boolean") }) typ.macroexp = where_macroexp @@ -6557,10 +6557,6 @@ local function show_type_base(t: Type, short: boolean, seen: {Type:string}): str end if t is NominalType then - if #t.names == 1 and t.names[1] == "@self" then - return "self" - end - local ret: string if t.typevals then local out = { table.concat(t.names, "."), "<" } @@ -8033,19 +8029,11 @@ do return arr_type end - local function is_self(t: Type): boolean - return t is SelfType or (t is NominalType and t.names[1] == "@self") - end - local function compare_true(_: TypeChecker, _: Type, _: Type): boolean, {Error} return true end function TypeChecker:subtype_nominal(a: Type, b: Type): boolean, {Error} - if is_self(a) and is_self(b) then - return true - end - local ra = a is NominalType and self:resolve_nominal(a) or a local rb = b is NominalType and self:resolve_nominal(b) or b local ok, errs = self:is_a(ra, rb) @@ -9076,7 +9064,8 @@ do if argdelta == -1 then from = 2 local errs = {} - if (not is_self(fargs[1])) and not self:arg_check(w, errs, fargs[1], args.tuple[1], "contravariant", "self") then + local first = fargs[1] + if (not first is SelfType) and not self:arg_check(w, errs, first, args.tuple[1], "contravariant", "self") then return nil, errs end end