DIPX: Enum Literals / Implicit Selector Expression

ryuukk_ ryuukk.dev at gmail.com
Sat Jun 25 16:10:03 UTC 2022


I tried to implement this, i spent the whole day today on it, 
unfortunately, i'm unable to make progress, to be honest, it was 
like diving in an endless ocean, i was clueless lol, if anyone is 
willing to help, that would be super cool, that feature deserve 
to be implemented!

Here is a test code:

```D
--- app.d
import data;

void main()
{
   pass_enum(MyEnum.MyValueB);
   pass_enum(.MyValueA);
}

--- data.d
module data;

enum MyEnum { MyValueA, MyValueB }

void pass_enum(MyEnum e) {}
```


The idea is:

1- call ``pass_enum`` with ``.MyValueA``
2- dmd should be able to know what symbol it refers to in the 
pass_enum function
3- dmd should check in all the known modules if he can find that 
symbol
4- if dmd found the symbol, check its members and compare both 
values
5- if it finds it, then use that symbol
6- if it doesn't find it, then fall back to the old behavior of 
checking in the module for values


I'm clueless about both DMD and language development, so that 
adds another layer of difficulty for me, trying to understand DMD 
code base, and overall how language and compiler works, i still 
have no clue how everything world.. but i still managed to get 
somewhere


I put an ``else`` here: 
https://github.com/dlang/dmd/blob/6f2a4daebabe666fbb5d9fde1aa6a0e6ddb6b70d/src/dmd/expressionsem.d#L12686

So the compiler doesn't complain about ``undefined identifier``, 
this allows me to start working on step 2, and that's where i got 
stuck..

If anyone is willing to help me, that would be sweet



More information about the Digitalmars-d mailing list