# Autogenerated :structInit constructor makes hl do funny things

**URL:** <https://community.haxe.org/t/autogenerated-structinit-constructor-makes-hl-do-funny-things/1417>\
**Category:** Haxe\
**Tags:** haxe-hl\
**Created:** [January 1, 2019, 10:33am UTC](https://community.haxe.org/t/autogenerated-structinit-constructor-makes-hl-do-funny-things/1417 "2019-01-01T10:33:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SaintAnne](https://avatars.discourse-cdn.com/v2/letter/s/65b543/32.png) [@SaintAnne](https://community.haxe.org/u/SaintAnne)\
**Post date:** [January 1, 2019, 10:33am UTC](https://community.haxe.org/t/autogenerated-structinit-constructor-makes-hl-do-funny-things/1417/1 "2019-01-01T10:33:18Z")

</div>

```haxe
@:structInit
@:publicFields
class State {
    var a:Int;
    var b:Array<String>;
    var c:Float;
    var d:Test;
    var e:Int;
    var f:Int;
    var g:Int;
    var h:Int;
    var i:Array<Int>;
}

class Test {
    public function new() {
    }

    public function x() {
        var a = Main.state.a;
        var b = Main.state.b;
        var c = Main.state.c;
        var d = Main.state.d;
        var e = Main.state.e;
        var f = Main.state.f;
        var g = Main.state.g;
        var h = Main.state.h;
        var i = Main.state.i;

        trace( 'a', a );
        trace( 'b', b );
        trace( 'c', c );
        trace( 'd', d );
        trace( 'e', e );
        trace( 'f', f );
        trace( 'g', g );
        trace( 'h', h );
        // trace( 'i', i ); // this kills hl
    }

    public function foo() {
        trace( this );
    }
}
class Main {
    public static var state:State;
    static var d:Test;
    static function main() {
        d = new Test();
        state = {
            a: 1,
            b: ["Hello", "world"],
            c: 3.14,
            d: d,
            e: 333,
            f: 444,
            g: 555,
            h: 666,
            i: [1, 2, 3, 4, 5, 6]
        };

        dododo();
    }

    static function dododo() {
        state.d.foo();
        d.x();
    }
}

```

output

```haxe
Main.hx:42: #Test
Main.hx:30: a, 1
Main.hx:31: b, [Hello,world]
Main.hx:32: c, 3.14
Main.hx:33: d, #Test
Main.hx:34: e, 333
Main.hx:35: f, 333
Main.hx:36: g, 333
Main.hx:37: h, 333

```

Works on neko. Uncommenting trace of i makes hl crash with MAV. Adding constructor to State manually makes it work.  
Test.foo() function is there because it’s actually possible to change _this_ of Test to one of an array (or maybe even to integer) but I’m yet not sure how, and didn’t manage to make it work in this example.
