When using operator overloading in Dart, are the operating functions resolved at compile time, or at runtime, or something else?
In which cases will the vm or dart2js be able to bypass something like this:
function add(left, right) {
if (isPrimitive(left) && isPrimitive(right)) {
return left + right;
} else if (left.hasOverload("+")) {
return left.plus(right);
} else if (left.hasReverseOverload("+")) {
return right.plus(left);
} else {
throw new Error("Cannot add objects");
}
}
Where in dart, maybe a + b
at compile time would be changed to add(a,b)
. This would be runtime checking, and for obvious reasons I have concerns about the performance of this. So basically, when in Dart if at all is runtime checking used?