Bug 15240 – errors in isExpression with == not gagged when used in constraint

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2015-10-23T08:47:00Z
Last change time
2015-10-23T15:48:32Z
Assigned to
nobody
Creator
r.sagitario

Comments

Comment #0 by r.sagitario — 2015-10-23T08:47:37Z
static if (is(R == what)) pragma(msg, "hi"); @property bool isDir(R)(R name) if (is(R == what)) { return true; } @property bool isDir(R)(R name) if (!is(R == what)) { return false; } void foo() { isDir!int(0); } The first line with the "static if" does not show an error, while the contraints produce: test.d(5): Error: undefined identifier 'what' test.d(10): Error: undefined identifier 'what' test.d(17): Error: template athis.isDir cannot deduce function from argument types !(int)(int), candidates are: test.d(5): athis.isDir(R)(R name) if (is(R : what)) test.d(10): athis.isDir(R)(R name) if (!is(R : what)) The same happens for ':' instead of '=='.
Comment #1 by k.hara.pg — 2015-10-23T13:50:23Z
This is intentional behavior. In 'IsExpression', if the Type operand is invalid, the latter arguments are not analyzed. In this case, the type R in `static if (is(R == what)) ...` is undefined, then what is not evaluated. If you supply R as a valid type, the 'what' will cause an error. alias R = int; static if (is(R == what)) pragma(msg, "hi"); Prints: --- test.d(2): Error: undefined identifier 'what'
Comment #2 by r.sagitario — 2015-10-23T15:48:32Z
Sorry, I reduced the issue too far. The actual case where it happened is in https://github.com/D-Programming-Language/phobos/pull/3764. This is similar to this which fails: enum check(R) = is(what) && is(R == what); @property bool isDir(R)(R name) if (check!R) { return true; } @property bool isDir(R)(R name) if (!check!R) { return false; } void foo() { isDir!int(0); } On the other hand, it compiles if check is declared as: template check(R) { static if (is(what) && is(R == what)) enum check = true; else enum check = false; } But that's documented special behaviour of "&&" for "static if", so I'll close this.