Why D functions paramter can not implicit infer type of Variant?

Ali Çehreli acehreli at yahoo.com
Wed Jan 13 17:29:12 UTC 2021


On 1/13/21 8:17 AM, Marcone wrote:

 > import std;
 >
 > void a(int b){
 > }
 >
 > void main()
 > {
 >    Variant c = 10;
 >    a(c); // Error
 > }
 >
 > Need more sugar.

That can't work in a strongly statically typed language. The call a(c) 
is decided at compile time but Variant is not an int at compile time.

It could only work if Variant were a user-defined type that had an 
automatic conversion to int with 'alias this'.

Ali



More information about the Digitalmars-d-learn mailing list