1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
/* <license>
* This file is part of the dis-Emi-A HaXe Library. Copyright © edA-qa mort-ora-y
* For full copyright and license information please refer to doc/license.txt.
* </license>
*/
/**
* This demonstrates a defect in HaXe, but one that only shows up when
* targeting Flash 9 (perhaps other versions as well). Perhaps it is
* ambigious as to what should happen, in which case the compiler should
* flag it as an error.
*
* If compiled to Neko the output is (as expected):
* D1:5
* B:5
* Check:{}
* D2:5
*
* But in Flash9, it looks like this:
* D1:5
* B:null
* Check:{}
* D2:null
*
* This seems to indicate that member variables in the super class may not
* be set prior to calling "super" in the derived class, *BUT* only if the type
* of the variable is a standard type, user-defined types do not seem to have
* this problem. Thus this caveat applies only to types like Dynamic, Int, Float,
* String, Null, ...
*/
class Base
{
var mem : Null<Int>;
var check : Hash<Int>;
public function new()
{
//trace( "B:" + mem );
//trace( "Check:" + check );
}
}
class Derived extends Base
{
public var okay : Bool;
public function new()
{
mem = 5;
check = new Hash<Int>();
//trace( "D1:" + mem );
okay = (mem == 5);
super();
//trace( "D2:" + mem );
okay = okay && (mem == 5);
}
}
class CtorNull extends haxe.unit.TestCase
{
public function testMain()
{
var d = new Derived();
assertTrue( d.okay );
}
}
|