Bug 23797 – Improve type-testing `is` expressions

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-03-21T14:45:51Z
Last change time
2024-12-13T19:27:55Z
Assigned to
No Owner
Creator
Bolpat
Moved to GitHub: dmd#20250 →

Comments

Comment #0 by qs.il.paperinik — 2023-03-21T14:45:51Z
Relevant section in the spec: https://dlang.org/spec/expression.html#is-identifier Relevant paragraph is 8, starting with “If TypeSpecialization is a valid keyword”. The syntax `is(Type == Keyword)` should be extended to allow for multiple space-separated keywords if the keywords are type constructors. E.g. `is(T == const shared)` would be equivalent to `is(T == const) && is(T == shared)`; it is surprising that “composed” type qualifiers do not work in this context, but in every other context. Additionally, one of `struct`, `union`, `class`, `interface`, `enum`, `function`, `delegate`, and maybe also `return` could be allowed together with type qualifiers, e.g. `is(T == const class)` is equivalent to `is(T == const) && `is(T == class)`. Another enhancement to consider is to allow `struct`, `union`, `class`, `interface`, `enum`, `__vector`, `function`, `delegate`, `const`, `immutable`, `inout`, `shared`, `module`, and `package` as the right-hand “operand” of what would normally be a binary `is` or `!is` expression, e.g. `T is class`, `T !is const`, and with the above enhancement `T is const class`, because they read much nicer and feel more correct, i.e. a type “is” a class type and does not “equal” to `class`.
Comment #1 by qs.il.paperinik — 2024-06-17T12:20:10Z
As for the right-hand side of `is(Type == Keyword)` for function pointer and delegate types, it also makes sense to ask if they’re carrying attributes. The keyword attributes should be allowed, but I think also user-defined ones should be allowed. Also visibility can be allowed for any symbols. The same for the simplified `is …` syntax. `DG is @nogc` is clear to read.
Comment #2 by nick — 2024-11-04T10:57:55Z
Just to note that `module` and `package` (already accepted), `return` and visibility should not be part of an `is` expression, because an `is` expression is supposed to test whether something is a valid type. It's not to test symbols. From the spec: "An IsExpression is evaluated at compile time and is used to check if an expression is a valid type."
Comment #3 by robert.schadek — 2024-12-13T19:27:55Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20250 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB