GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Inheriting classes won't call constructor of their super class · Issue #187 · AssemblyScript/assemblyscript

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Inheriting classes won't call constructor of their super class#187
Copy link
Labels
bug

Description

@kyasbal
kyasbal
opened on Jul 25, 2018
Issue body actions

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?

Activity

  1. dcodeIO commented on Jul 25, 2018

    @dcodeIO
    dcodeIO
    on Jul 25, 2018
    Member
    More actions

    Class support is still relatively basic and when looking at the generated text format it appears that the super call is compiled incorrectly. Seems that its arguments are compiled, but just dropped instead of calling anything with them.

     (func $tests/compiler/empty/Texture4CH#constructor (; 6 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
      (local $3 i32)
      (drop
       (get_local $0) (; this ;)
      )
      (drop
       (get_local $1) (; width ;)
      )
      (drop
       (get_local $2) (; height ;)
      )
      (drop
       (i32.const 4) (; 4 ;)
      )
      ...
  2. dcodeIO
    added
    bug
    on Jul 25, 2018
  3. trusktr commented on Dec 11, 2018

    @trusktr
    trusktr
    on Dec 11, 2018
    Member
    More actions

    I haven't tried yet, but can we work around this by using a method instead of relying on constructors? F.e. an init method that you just have to remember to call, const foo = new Foo(); foo.init();.

  4. MaxGraey commented on Feb 7, 2019

    @MaxGraey
    MaxGraey
    on Feb 7, 2019
    Member
    More actions

    @dcodeIO could we close this as well?

  5. dcodeIO
    closed this as completedon Feb 7, 2019
  6. dcodeIO commented on Feb 7, 2019

    @dcodeIO
    dcodeIO
    on Feb 7, 2019
    Member
    More actions

    Yeah, should be fixed meanwhile. Feel free to reopen if there are still any issues!

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.