Type Inference for Struct/Enum Literals

Nick Treleaven nick at geany.org
Sun Jul 7 19:42:25 UTC 2024


On Friday, 5 July 2024 at 13:19:44 UTC, IchorDev wrote:
> The specifics of how this interacts with existing features 
> (e.g. array literals) very much depends on how *those* features 
> infer type. Here's a good example:
> ```d
> Enum getEnum() => .bar; //OK: return type is an enum with 
> member `bar`
> Enum x = (() => .bar)(); //it's probably not worth trying to 
> make this work
> auto y = (int num){
> 	switch(num){
> 		case 0: return Enum.foo;
> 		case 1: return .bar; //this will only work if D's compiler 
> frontend knows the return type of this lambda based on the 
> first return statement.
> 		default: assert(0);
> 	}
> }(1);
> ```

Just to mention that Vladimir's idea of making an identifier 
expression have its own type should work for all the cases above, 
with minimal compiler complexity.
https://forum.dlang.org/post/ysbmglpkvygrpjsggqco@forum.dlang.org

However, that doesn't seem to help for an implicit struct 
construction expression.


More information about the dip.ideas mailing list