DIP1044---"Enum Type Inference"---Formal Assessment

Steven Schveighoffer schveiguy at gmail.com
Thu May 11 15:47:54 UTC 2023


On 5/11/23 10:10 AM, Paul Backus wrote:
> On Thursday, 11 May 2023 at 13:31:58 UTC, Steven Schveighoffer wrote:
>> On 5/10/23 11:22 PM, Paul Backus wrote:
>>> In fact, for this particular example, there are actually two enums in 
>>> the DMD source code that these symbols could be coming from: `enum 
>>> TargetOS` in `cli.d`, and `enum OS` in `target.d`. So you would have 
>>> to scroll up and look at the imports to disambiguate.
>>
>> Then you misunderstand the DIP (as did Walter). There is only one enum 
>> that can be involved -- typeof(target.os).
> 
> Oh no, I'm perfectly aware that, from the compiler's perspective, it 
> would be unambiguous--only one of the two enums would actually be in 
> scope.

Scope has nothing to do with it. The wrong enum might be the only one in 
scope, and it will still use the correct one. Both enums might be in 
scope, and it still uses the correct one.

> But as a human reader, in order to figure out which one, I'd have 
> to scroll to the top of the file and read through ~25 lines of imports 
> (or rely on tooling, but there are contexts where that isn't available, 
> like a Github code review).

It's no different than:

```d
if(target.os == target.os.Solaris)
```

It's not very hard to understand, nor harder to figure out. What type is 
`target.os`? It's an enum from that type.

-Steve


More information about the Digitalmars-d-announce mailing list