Skip to content

Emit incorrect debugLocation while convertExpression() #2833

Description

@XMadrid

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

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions