GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — loop with try catch body emitted invalid lua code · Issue #1598 · TypeScriptToLua/TypeScriptToLua

loop with try catch body emitted invalid lua code #1598

New issue
Copy link
New issue
Copy link
Open
#1741
Open
loop with try catch body emitted invalid lua code#1598
#1741
Copy link
Labels
bugscope: transformationTransformation of TS to LuaTransformation of TS to Lua

Description

@admiralnelson
admiralnelson
opened on Nov 19, 2024
Issue body actions
const factionKeys = [
    "bretonnia1",
    "bretonnia1",
    "bretonnia1",
    "bretonnia1",
    "bretonnia12"
]

declare interface OpaqueObject {}
declare function GetFaction(factionKey: string) : OpaqueObject

for (const f of factionKeys) {
    try {
        const nativeInterface = GetFaction(f)
    } catch {
        break
    }
}

for (let i = 0; i < factionKeys.length; i++) {
    try {
        const nativeInterface = GetFaction(f)
    } catch {
        break
    }
}

while(true) {
    try {
        const nativeInterface = GetFaction(factionKeys[0])
    } catch {
        break
    }
}

do {
    try {
        const nativeInterface = GetFaction(factionKeys[0])
    } catch {
        break
    }
} while (!false)

output

--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
factionKeys = {
    "bretonnia1",
    "bretonnia1",
    "bretonnia1",
    "bretonnia1",
    "bretonnia12"
}
for ____, f in ipairs(factionKeys) do
    do
        local function ____catch()
            break  -- <-- this caused syntax error
        end
        local ____try = pcall(function()
            local nativeInterface = GetFaction(nil, f)
        end)
        if not ____try then
            ____catch()
        end
    end
end
do
    i = 0
    while i < #factionKeys do
        do
            local function ____catch()
                break -- <-- this caused syntax error
            end
            local ____try = pcall(function()
                local nativeInterface = GetFaction(nil, f)
            end)
            if not ____try then
                ____catch()
            end
        end
        i = i + 1
    end
end
while true do
    do
        local function ____catch()
            break -- <-- this caused syntax error
        end
        local ____try = pcall(function()
            local nativeInterface = GetFaction(nil, factionKeys[1])
        end)
        if not ____try then
            ____catch()
        end
    end
end
repeat
    do
        do
            local function ____catch()
                break -- <-- this caused syntax error
            end
            local ____try = pcall(function()
                local nativeInterface = GetFaction(nil, factionKeys[1])
            end)
            if not ____try then
                ____catch()
            end
        end
    end
until false

playground link
https://typescripttolua.github.io/play/#code/MYewdgzgLgBAZgQ2FAluA0gUwJ4RgXhgG0AoGcmAIgCMAnTKcMFBARkoBoyKb7GxmbTt3K8GTFuy4UqdcQMnCZY-oNYAmSiQC6JEgBNMwADYJ6MFGCiZaiYJhgB5AA4IAjgFdMj6gCsjsADeAL4GRqbmcB5gyGhgMADiDABiSKjgABR26WBY2ABcMNC0lgDmAJQwhS7uXj7+yHpwILQwGaCQsHAwIN3ZcXkQlYEiMFC02DAjMjId0DBgCKgAbpgAklY2dg6ESVCpsZlw5aPBMMBLwAAWU6MycggA1qckoSTNrRnGDBYEMAAMAG5fgAeeBpAY4CAAOm+YFKUCuwJQAGoUcNRuNJtMZuQ5rBFit1ptbEgdokUhCjicZGcLlBrrdceQHs9aa89AB3K4ob4ZcZeDEyLFM5n4hZLFCrDbWUn2P57A45LJU3JQoj-bQ0ih0y43HG41kvN76ECi8gig0zcWEqXE2XbBWUw5gFUuwYarWnc5680zI3ss7c3kODIAQkQxggmHKQA

Reacted by walking

Activity

  1. jamesWalker55 commented on Nov 20, 2024

    @jamesWalker55
    jamesWalker55
    on Nov 20, 2024
    More actions

    Having the same issue here. Here's a minimal example.

    TypeScript:

    while (true) {
        try {
            error("foo")
        } catch (e) {
            break;
        }
    }

    Generated Lua:

    while true do
        do
            local function ____catch(e)
                break
            end
            local ____try, ____hasReturned = pcall(function()
                error("foo")
            end)
            if not ____try then
                ____catch(____hasReturned)
            end
        end
    end

    Seems having the break inside a function is causing the error.

    Playground link

  2. Perryvw
    added
    bug
    scope: transformationTransformation of TS to LuaTransformation of TS to Lua
    on Nov 21, 2024
  3. admiralnelson commented on Nov 28, 2024

    @admiralnelson
    admiralnelson
    on Nov 28, 2024
    Author
    More actions
    for (const f of factionKeys) {
        try {
            const nativeInterface = GetFaction(f)
            break //<-- this causes the same problem
        } catch {
            break
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugscope: transformationTransformation of TS to LuaTransformation of TS to Lua

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.