HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.03k stars 648 forks source link

Invalid operation on setter when using null field access #11592

Closed Jarrio closed 4 months ago

Jarrio commented 4 months ago

Demo: https://try.haxe.org/#871345F4

If you remove the ? from the line things work fine. I'm not exactly sure what the issue is specifically, but, the error should probably be clearer as well

Code:

class Test {
  static function main() {
    var bar = new Bar();
    trace(bar.stuff);
  }
}

class Bar {
  var foo = new Foo();
    var values(get, never):Data;
  function get_values() {
        return foo?.value;
  }

  public var stuff(get, set):Float;
  function get_stuff() {
        return values?.stuff;
  }

  function set_stuff(value:Float) {
        return values?.stuff = value; // error here
  }

  public function new() {}
}

class Foo {
  public var value:Data = new Data(32);
  public function new() {}
}

class Data {
    public var stuff:Float;
  public function new(data) {
        this.stuff = data;
  }
}
RblSb commented 4 months ago

Already fixed in dev, see https://github.com/HaxeFoundation/haxe/issues/11379

Jarrio commented 4 months ago

Already fixed in dev, see #11379

Ah yes, my bad I should have checked. Thanks!