Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for forward references to global interfaces and aliases, and mutually recursive types #68

Closed
mascarenhas opened this issue Mar 10, 2016 · 0 comments

Comments

@mascarenhas
Copy link
Collaborator

Global interfaces and type aliases may be used in declarations before they are actually declared, as long as there is no interving code that needs the declarations for typechecking (Typed Lua is still a single-pass compiler). This should also allow the declaration of mutually recursive interfaces and type aliases. An example:

-- The following two mutually recursive types are the same structurally
interface Tree1
  label: integer
  left: Tree2?
  right: Tree2?
end

interface Tree2
  label: integer
  left: Tree1?
  right: Tree1?
end

-- the following type has a forward reference
interface OBJ
   parent: OBJ?
   atr: ELEM
end

interface ELEM
   x: integer
end

local function f(o:OBJ)
   local t1: Tree1 = { label = 2 }
   local t2: Tree2 = { label = 3 }
   t1 = t2 -- ok because Tree2 <: Tree2
   t2 = t1 -- ok because Tree1 <: Tree2
   local parent = o.parent
   if parent then
      f({atr={x=2}})
   end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant