@@ -11067,6 +11067,9 @@ local traverse_nodes = traversal.traverse_nodes
1106711067local util = require("teal.util")
1106811068local sorted_keys = util.sorted_keys
1106911069
11070+ local types = require("teal.types")
11071+
11072+
1107011073local lua_compat = {}
1107111074
1107211075
@@ -11262,9 +11265,13 @@ local function adjust_code(ast, needs_compat, gen_compat, gen_target)
1126211265 visit_node.cbs["op"] = {
1126311266 after = function(_, node, _children)
1126411267 if node.op.op == "is" then
11265- if node.e2.casttype.typename == "integer" then
11268+ local ct = node.e2.casttype
11269+ while ct.typename == "nominal" and ct.resolved do
11270+ ct = ct.resolved
11271+ end
11272+ if ct.typename == "integer" then
1126611273 needs_compat["math"] = true
11267- elseif node.e2.casttype .typename ~= "nil" then
11274+ elseif ct .typename ~= "nil" then
1126811275 needs_compat["type"] = true
1126911276 end
1127011277 elseif node.op.op == "." then
@@ -11985,11 +11992,15 @@ function lua_generator.generate(ast, gen_target, opts)
1198511992 elseif node.op.op == "as" then
1198611993 add_child(out, children[1], "", indent)
1198711994 elseif node.op.op == "is" then
11988- if node.e2.casttype.typename == "integer" then
11995+ local ct = node.e2.casttype
11996+ while ct.typename == "nominal" and ct.resolved do
11997+ ct = ct.resolved
11998+ end
11999+ if ct.typename == "integer" then
1198912000 table.insert(out, "math.type(")
1199012001 add_child(out, children[1], "", indent)
1199112002 table.insert(out, ") == \"integer\"")
11992- elseif node.e2.casttype .typename == "nil" then
12003+ elseif ct .typename == "nil" then
1199312004 add_child(out, children[1], "", indent)
1199412005 table.insert(out, " == nil")
1199512006 else
0 commit comments