Unbound variable - inline bug

28 views
Skip to first unread message

Ondřej Műller

unread,
Jul 6, 2016, 7:45:04 PM7/6/16
to Haxe
I saw an open issue for inline cpp branching, don't know if this falls under it:

Error: While running :cl.exe ...
./src/ImageEditor1.cpp(517) : error C2065: 'view_bytes' : undeclared identifier

.cpp:

{
view_bytes->setFloat(view_pos,(int)1);
hx::AddEq(view_pos,(int)4);
}

There's no mention view_bytes anywhere else. view is a CLASS instance with a bytes variable. My original code had this constructor:

public inline function new(bytes:Bytes, pos:Int = 0) {
if (bytes != null) this.bytes = bytes;
this.pos = pos;
}

and I got the error every time I called any inlined method of the class which used a method of bytes.

It boiled down to this example:

package;

class A {
public function new() {}
public function f() {}
}
class B {
public var a:A;
public inline function new() {
if (a != null) a = new A();
a.f();
}
}
class Main {
public static function main() {
var b = new B();
}
}

Which, even before generating anything, says:

Unbound variable, please report this
{
        v_id = 379;
        v_name = b_a;
        v_type = A;
        v_capture = false;
        v_extra = None;
        v_meta = [@:inlineConstructorVariable];
}
While analyzing Main.main
dot graph written to dump/flash/Main.main
File "src/optimization/analyzerTypes.ml", line 221, characters 3-9: Assertion failed
There's more if it's in debug mode.

There needs to be a method of the variable called or there's no error. It can by in any inlined function, eg the constructor.
If the comparison is (bytes == null), the compiler probably resolves this to true as the outcome is different.
If the comparison does not contain the variable eg (Math.random() > 0.5), it just says "Main.hx:17: characters 10-17 : Unbound variable b_a".
If I declare bytes with var bytes:Bytes = null, it compiles and runs.
Reply all
Reply to author
Forward
0 new messages