HaxeFoundation / HaxeFoundation/hxcpp
Calling a method on a null value class is allowed.
- Dominant language
- C++
- Stars
- 330
- Forks
- 227
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 18
Description
If you have an array of classes and you try and index a non-existent index. It will allow you to call methods just fine. But if said method tries to access a variable of the class it will crash, because `this` is null (however it can call other methods of itself)
This is very weird behaviour to me, but it might be intentional.
```hx
class CoolClass {
public var num:Int;
public function new(i:Int) {
num = i;
}
public function hi() {
trace(this);
trace(num);
}
}
class Main {
static function main() {
trace('Begin');
var myCoolClasses:Array = [];
myCoolClasses.push(new CoolClass(1));
myCoolClasses.push(new CoolClass(2));
// Index 0 and 1 available, lets call indexes 0, 1 and 2
myCoolClasses[0].hi();
myCoolClasses[1].hi();
myCoolClasses[2].hi();
trace("End");
}
}
```

Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.