Bug 24033 – [compiler diagnostics] Add a way to make aliases "strong"

Status
NEW
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-07-06T12:02:11Z
Last change time
2024-12-13T19:30:03Z
Assigned to
No Owner
Creator
Bolpat
Moved to GitHub: dmd#18179 →

Comments

Comment #0 by qs.il.paperinik — 2023-07-06T12:02:11Z
This is not about language semantics, but compiler diagnostics only. Aliases are weak in the sense that error messages resolve aliases: ```d alias ints = int[]; void f(ints xs); pragma(msg, typeof(&f)); // void function(int[] xs) ``` The only exceptions are `string`, `wstring`, and `dstring`: ```d void f(immutable(char)[] str); pragma(msg, typeof(&f)); // void function(string str) ``` The string aliases aren’t like regular aliases: Their alias name is displayed instead of the type they alias. It might be of great pleasure to users if any alias could be marked "strong" by the programmer, so that the alias appears in diagnostics and not the aliased type. Of course, for each type, there must not be multiple different "strong" aliases. --- There are several possibilities: * re-use the `typedef` keyword: `typedef ints = int[];` * introduce an @attribute: `@strong alias ints = int[];` (applicable to `alias` only) * introduce a pragma: `pragma(strong) alias ints = int[];` (applicable to `alias` only) * introduce a trait: `__traits(strong) alias ints = int[]; (applicable to `alias` only) This is especially useful for templates with optional parameters where users are generally not interested in the defaults.
Comment #1 by robert.schadek — 2024-12-13T19:30:03Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18179 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB