D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20776 - No error is given out for wrong static if expression
Summary: No error is given out for wrong static if expression
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 critical
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-27 03:26 UTC by Heromyth
Modified: 2020-04-27 09:38 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Heromyth 2020-04-27 03:26:30 UTC
No any error is given out while compiling when a undefined function used in static if


Here is the test code:

import std.stdio;
// import std.traits; // Forgot to import this, then no error is given out while compiling

void test(T)() {

    static if(is(T : K[], K) && is(Unqual!K == ubyte)) {
        writeln("OK");
    } else {
        writeln("Wrong");
    }
}

void main() {
    test!(const(ubyte)[]);
}
Comment 1 moonlightsentinel 2020-04-27 09:38:56 UTC
This is the expected behaviour of an is-expression. Unqal is not a function but a template aliasing to another type. `Unqal!K` isn't a valid type once you omit the import which causes the `is` to evaluate to false.

> Type is the type being tested. It must be syntactically correct, but it
> need not be semantically correct. If it is not semantically correct, the
> condition is not satisfied.

See https://dlang.org/spec/expression.html#is_expression