Skip to content

Instantly share code, notes, and snippets.

@boozook
Last active November 18, 2015 13:30
Show Gist options
  • Save boozook/f4127d51c1abb8b48621 to your computer and use it in GitHub Desktop.
Save boozook/f4127d51c1abb8b48621 to your computer and use it in GitHub Desktop.
Haxe Java Abstract(:Float) Inline Increment test (issue #4649)
-main Test
# same result without analyzer too
-D analyzer
-D dump=pretty
--each
-cpp bin
-cmd ./bin/Test
# OK
--next
-neko bin/Test.n
-cmd neko bin/Test.n
# OK
--next
-swf bin/Test.swf
-cmd open bin/Test.swf
# OK
--next
-php bin
-cmd php bin/index.php
# OK
--next
-js bin/Test.js
-cmd node bin/Test.js
# OK
--next
-java bin
-cmd java -jar bin/Test.jar
# FAIL
private class _Test.Val_Impl_{
static public incrmnt(inline method) : this : Val.T -> Void
= function(this1:Val.T) = {
this1 ++;
}
}
class Test extends haxe.unit.TestCase{
public testAbstractInlineIncrement(method) : Void -> Void
= function() = {
var a = 42;
var b = 1.42;
this.assertEquals(42,a,{fileName : "Test.hx",lineNumber : 34,className : "Test",methodName : "testAbstractInlineIncrement"});
this.assertEquals(1.42,b,{fileName : "Test.hx",lineNumber : 35,className : "Test",methodName : "testAbstractInlineIncrement"});
a ++;
b ++;
this.assertEquals(43,a,{fileName : "Test.hx",lineNumber : 39,className : "Test",methodName : "testAbstractInlineIncrement"});
this.assertEquals(2.42,b,{fileName : "Test.hx",lineNumber : 40,className : "Test",methodName : "testAbstractInlineIncrement"});
haxe.Log.trace("A: " + a,{fileName : "Test.hx",lineNumber : 42,className : "Test",methodName : "testAbstractInlineIncrement"});
haxe.Log.trace("B: " + b,{fileName : "Test.hx",lineNumber : 43,className : "Test",methodName : "testAbstractInlineIncrement"});
}
}
$ haxe build.hxml
...
haxelib run hxjava hxjava_build.txt --haxe-version 3201 --feature-level 1
javac "-sourcepath" "src" "-d" "obj" "-g:none" "@cmd"
src/_Test/Val_Impl_.java:15: error: incompatible types: double cannot be converted to T
this1 = ( __temp_ret1 + 1.0 );
^
where T is a type-variable:
T extends Object declared in method <T>incrmnt(T)
1 error
Compilation error
Native compilation failed
Error: Build failed
import haxe.unit.*;
abstract Val<T:Float>(T) from T to T
{
public inline function incrmnt():Void this++; // HERE
}
class Test extends TestCase
{
function testAbstractInlineIncrement()
{
var a:Val<Int> = 42;
var b:Val<Float> = 1.42;
assertEquals(42, a);
assertEquals(1.42, b);
a.incrmnt();
b.incrmnt();
assertEquals(43, a);
assertEquals(2.42, b);
trace('A: $a');
trace('B: $b');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment