Skip to content

Weird behavior with constructor parameter properties #1225

Closed
@surma

Description

@surma

This was a weird one to track down. Here’s a reduced reproduction.

class X {
  public normal: i32;
  public viaThis: i32;
  constructor(private x: i32) {
    this.viaThis = this.x;
    this.normal = x;
  }
}

const x = new X(4);
export function normal(): u32 {
  return x.normal;
}
export function viaThis(): u32 {
  return x.viaThis;
}
console.assert(instance.exports.normal() === 4);
// This will throw. With asc 0.9.4 it will return `0`
console.assert(instance.exports.viaThis() === 4); 

Fun fact: If you swap the assignments in the constructor, both return 4 🤷

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