Skip to content

[ECMA] return in finally ignored in async functions when try also returns #1719

@RealColdFry

Description

@RealColdFry

Repro:

// Issue: finally block overrides try's return value
async function finallyReturn(): Promise<string> {
    try {
        await Promise.resolve();
        return "try";
    } finally {
        return "finally";
    }
}

finallyReturn().then(v => console.log(v));
// Expected (JS): "finally"

Playground link:
https://typescripttolua.github.io/play/#code/5.4/PTAEEkGdIVwUwFygGYEsB2BDANtgnqAEbYD2AxgNagkBucATvagCZySgAu9eA5O-XA4x66UDRzwAUJkh50ZFDHkdUJUWiy48AJUHD0ACgCUSAAr0SAW1SQ4AHkhcMAcwB8oAN6TQPzt0-evkGYAO6YqByg5lY2cAB0ApAk2HTGANyBQT4CQiKgAERcePkZQQC+KBg4+AFZvjn6BRrVxaW+ZZIdks1aurmGRnEcABZwhjSgALzuZGpJ2PGkzgY0RkYZIKAAogAeAA5wZBxwzKAGAFIAyiZNVVr5kkA

ECMA spec ref: https://tc39.es/ecma262/#sec-try-statement-runtime-semantics-evaluation


note, sync works:

function f() {
  try {
    return "try";
  } finally {
    return "finally";
  }
}

console.log(f());

https://typescripttolua.github.io/play/#code/5.4/GYVwdgxgLglg9mABMAFASkQbwFCMVAJwE8tc9ECBTKEApAIkKPoG4yBfZGMAQwBs+JHOQrVaDYN36DWHbO2zYICAM5w+lAHR84AcxSo0aNkA

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions