Hi everyone, I have a few questions:
1) Is the compiler able to warn about potential mistakes like variable1 == variable2; ? Here the value of the boolean expression isn't used, which suggests this may not be what the programmer intended to do. (In my case, I intended variable1 = variable2, spent 2 hours last night looking for my goof.)
2) Regarding non-nullable default parameters. Consider the following code:
class Main {
static function main() {
defaultParams(1);
}
static function defaultParams(b = true, i = 1) { }
}
This compiles fine on Neko and C++, but on Flash the compiler gives the error "Cannot skip non-nullable argument b". The error goes away if the compiler is able to infer b as having type Null<Bool> instead of Bool, through ?b = true or b:Null<Bool> = true. But what's strange is that:
- like Flash, C++ is also a static target, yet compiling to C++ doesn't produce an error
- omitting all optional params until the end is fine, e.g. defaultParams(); defaultParams(false); will compile. But skipping some non-nullable params and providing some later on is not.
So what exactly is the compiler doing?
3) I'd like a Map whose keys are general objects, and to return the same value when two objects having the same data (but not necessarily with the same reference) are queried. But Map only does this for Strings.
What I'm currently doing is
typedef MyObjData = {
var data1:Data1;
var data2:Data2;
}
@:forward(data1, data2)
abstract MyObj(MyObjData) from MyObjData to MyObjData {
...
@:to
inline public function toID():String {
... //return string encoding of the data
}
}
which allows me to use a Map<String, MyValue> via array access on MyObj indices. But is there a way to use a Map<MyObj, MyValue> instead and still have keys be compared by value instead of by reference?
Haxe's == operator compares Bools, Ints, Floats and Strings by value, and all other objects by reference, does it have something to do with this? I've tried overloading == to compare MyObjs as well, but Map still compares them by reference.