dlang-community / D-Scanner

Swiss-army knife for D source code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add check for `is(T : ...)` tests testing for noreturn

WebFreak001 opened this issue · comments

See https://forum.dlang.org/thread/xmjabqpofltdwxfqlwhi@forum.dlang.org

code like

struct Something(Types...) {}

enum isSomething(T) = is(T : Something!Types, Types...);

might be how users write custom is-checks to see if a given type is some templated type, however for isSomething!noreturn this returns true, which might be unexpected for the user. (see forum discussion)

My check idea to add would be warning if noreturn isn't explicitly handled for global templates or maybe even everywhere. (could be configurable)

so for the code above it would give a warning and the user would have a few choices to fix it:

// noreturn is not Something
enum isSomething(T) = is(T : Something!Types, Types...)
    && !is(immutable T == immutable noreturn);

// noreturn is Something
enum isSomething(T) = is(T : Something!Types, Types...)
    || is(immutable T == immutable noreturn);

// only match exact Something (no alias this support anymore though)
enum isSomething(T) = is(T == Something!Types, Types...);

to keep the check simple it would just check for any is(T : ...) expression and see if in the same expression or template T is compared with noreturn.