But still the crux is the compiler resolves any variant type at
run-time, not compile time..... Even if it can somehow know how it can be resolved into a valid compile time type.
(It should not even attempt to do that)
The theory is well described here:
https://en.wikipedia.org/wiki/Tagged_union Demo - this compiles!! as it should:
{$mode delphi}{$H+}
var
a,b:Variant;
begin
a:= 0; // valid
b:='Test'; // valid
writeln(a+b); // run-time error, I hope, guess what? I does!!! Happy...
end.
Ergo, don't use variants unless you know what you are doing.
Worse: if you actually
know it can be resolved at compile time you are a complete moron to use a variant type. Use the proper type.
This is not even open for discussion.... IMNSHO
We are not copying from Delphi, alas, as the theory is implemented as it should be.
I have the faint idea you will refuse to understand this anyway.
Sometimes you have to put in some more effort in trying to understand things.