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

Emit incorrect debugLocation while convertExpression() #2833

Open
XMadrid opened this issue Apr 1, 2024 · 0 comments · May be fixed by #2835
Open

Emit incorrect debugLocation while convertExpression() #2833

XMadrid opened this issue Apr 1, 2024 · 0 comments · May be fixed by #2835
Labels

Comments

@XMadrid
Copy link
Contributor

XMadrid commented Apr 1, 2024

Bug description

function main(): void {
  add(1, 2);
}

For above code snippet, assemblyscript wraps a drop for the call add instruction. But there is no debuglocation for call instruction.

Steps to reproduce

The root cause is that, in the following code in assemblyscript. When asc wrap a drop epxr for the call epxr by execute convertExpression(), the expr variable(call expr) will be overwritten with (drop expr). And then addDebugLocation(drop). When returning to compileStatement after compileExpression, asc will addDebugLocation(drop) again. So we missed the debugLocation for call expr.

In src/compiler.ts line 3453-3468,

    if (currentType != contextualType.nonNullableType) { // allow assigning non-nullable to nullable
      if (constraints & Constraints.ConvExplicit) {
        expr = this.convertExpression(expr, currentType, contextualType, true, expression);
        this.currentType = currentType = contextualType;
      } else if (constraints & Constraints.ConvImplicit) {
        expr = this.convertExpression(expr, currentType, contextualType, false, expression);
        this.currentType = currentType = contextualType;
      }
    }
    if (wrap) expr = this.ensureSmallIntegerWrap(expr, currentType);
    // debug location is added here so the caller doesn't have to. means: compilation of an expression
    // must go through this function, with the respective per-kind functions not being used directly.
    if (this.options.sourceMap) this.addDebugLocation(expr, expression.range);

AssemblyScript version

0.27.25

@XMadrid XMadrid added the bug label Apr 1, 2024
@XMadrid XMadrid linked a pull request Apr 3, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant