Skip to content

Commit

Permalink
self: remove magic behavior for nominal "@self"
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Aug 19, 2024
1 parent 0533ec1 commit 2eb09c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 28 deletions.
17 changes: 3 additions & 14 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, "."), "<" }
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
17 changes: 3 additions & 14 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, "."), "<" }
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2eb09c1

Please sign in to comment.