Bug 15550 – [Reg 2.070.0-b1] compile error while testing template constraint

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2016-01-10T23:47:00Z
Last change time
2016-01-31T14:58:55Z
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2016-01-10T23:47:42Z
cat > bug.d << CODE struct Vector(T, int N) { void opDispatch(string, U)(U) { } } struct Matrix(T, int R, int C) { Matrix!(T, R, U._C) opBinary(string op, U)(U) // this constraint causes a compile error (even though the first test already fails) if (is(typeof(U._isMatrix)) && (U._R == C) && (op == "*")) { return Matrix!(T, R, U._C)(); } Vector!(T, R) opBinary(string op)(Vector!(T, C) x) { return Vector!(T, R)(); } enum _R = R; enum _C = C; enum bool _isMatrix = true; } unittest { Matrix!(int, 2, 2) z; auto z2 = z * z; // works static assert(!is(typeof(Vector!(int, 2)._isMatrix))); z * Vector!(int, 2)(); // errors on template constraint } CODE dmd -c -unittest bug ---- math/gfm/math/matrix.d(11): Error: void has no value math/gfm/math/matrix.d(11): Error: incompatible types for ((opDispatch!"_R") == (2)): 'void' and 'int' ---- There is something broken w/ the evaluation of template constraints. if (is(typeof(U._isMatrix)) && (U._R == C) && (op == "*")) In here the IsExp is already false, so the rest shouldn't get evaluated.
Comment #1 by code — 2016-01-16T17:46:50Z
The bug boils down to this behavior change. cat > bug.d << CODE struct Vector(T, int N) { void opDispatch(string, U)(U) { } } static assert(!is(typeof(Vector!(int, 2)._isMatrix))); CODE dmd -c -o- bug ---- bug.d(9): Error: static assert (!true) is false ---- It works w/ 2.069.2.
Comment #2 by code — 2016-01-16T18:32:08Z
Comment #3 by aliloko — 2016-01-19T12:12:25Z
Thanks Martin for reporting this!
Comment #4 by aliloko — 2016-01-19T12:32:12Z
- Still happen in DMD 2.071-b - Can't reproduce on Windows FWIW I could change the code, but I don't seem to find a workaround. I've tried std.traits.hasMember instead and it fails similarly.
Comment #5 by aliloko — 2016-01-19T22:32:24Z
Found a work-around.
Comment #6 by github-bugzilla — 2016-01-27T12:36:43Z
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/3d385e420a2daa6ad65aa4bbfcb27f582f3db60a Revert "Merge pull request #5263 from 9rnsr/fix15239" This reverts commit b72609a186dc4c3447cc60d94265c7b4e2a71768, reversing changes made to a7146f3fbb421daec178e0863e07ec10c267eb26. Reverting this fixes Issue 15550 https://github.com/D-Programming-Language/dmd/commit/682687b1739445db2d549f174fd1b7c1210cdc47 Merge pull request #5368 from MartinNowak/fix15550 fix Issue 15550 - compile error while testing template constraint
Comment #7 by github-bugzilla — 2016-01-31T14:58:55Z