www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23797] New: Improve type-testing `is` expressions

https://issues.dlang.org/show_bug.cgi?id=23797

          Issue ID: 23797
           Summary: Improve type-testing `is` expressions
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: qs.il.paperinik gmail.com

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`.

--
Mar 21 2023