Skip to content

Inheriting classes won't call constructor of their super class #187

Closed
@kyasbal

Description

@kyasbal

I have written this bunch of code to operate texture passed from WebGL.

export class U8_4 {
  constructor(public x: u8, public y: u8, public z: u8, public w: u8) {}
}

export class Texture {
  public baseAddress: u32 = 0

  public width: u16 = 0

  public height: u16 = 0

  public ch: u8 = 0

  constructor(width: u16, height: u16, ch: u8) {
    this.baseAddress = memory.allocate(<u32>(width * height * <u16>ch))
    this.width = width
    this.height = height
    this.ch = ch
    //*************************************************
    //There are problems here
    //*************************************************
    console.logi(123456) // This logging is not called
  }

  public getAddressAt(i: u16, j: u16): u32 {
    return (<u32>i * <u32>this.width + <u32>j) * <u32>this.ch
  }
}

export class Texture4CH extends Texture {
  constructor(width: u16, height: u16) {
    super(width, height, 4)
    console.logi(width)
    console.logi(height)
  }

  public getAt(i: u16, j: u16): U8_4 {
    let ba: u32 = this.getAddressAt(i, j)
    let x: u8 = load<u8>(ba, 0)
    let y: u8 = load<u8>(ba, 1)
    let z: u8 = load<u8>(ba, 2)
    let w: u8 = load<u8>(ba, 3)
    return new U8_4(x, y, z, w)
  }

  public setAt(i: u16, j: u16, col: U8_4): void {
    let ba: u32 = this.getAddressAt(i, j)
    store<u8>(ba, col.x, 0)
    store<u8>(ba, col.y, 1)
    store<u8>(ba, col.z, 2)
    store<u8>(ba, col.w, 3)
  }
}

As you can see, I have inherited Texture class from Texture4CH. When I instanciate Texture4CH class, the super notation super(width, height, 4) seems not working as intended.
Is this intended limitation of assemblyscript?

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