Skip to content

Commit

Permalink
tests: add test case using self
Browse files Browse the repository at this point in the history
See #756.
  • Loading branch information
hishamhm committed Aug 19, 2024
1 parent 2eb09c1 commit 7d000b8
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions spec/subtyping/self_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
local util = require("spec.util")

describe("subtyping of self", function()
it("self type resolves from abstract interface to concrete records (#756)", util.check([[
local interface SoundMaker
make_sound: function(self)
end
local record Animal is SoundMaker
species: string
end
function Animal:create(species: string): Animal
return setmetatable({ species = species }, { __index = Animal })
end
function Animal:make_sound()
print("Animal sound")
end
local record Person is SoundMaker
name: string
end
function Person:create(name: string): Person
return setmetatable({ name = name }, { __index = Person })
end
function Person:make_sound()
print("Person sound")
end
local things: {SoundMaker} = {
Animal:create("Dog"),
Person:create("John")
}
for _, thing in ipairs(things) do
thing:make_sound()
end
]]))
end)

0 comments on commit 7d000b8

Please sign in to comment.