Bug 8686 – Tuple cannot define with type that has only mutable opEquals

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-18T07:01:00Z
Last change time
2012-09-22T11:27:04Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
zan77137

Comments

Comment #0 by zan77137 — 2012-09-18T07:01:43Z
On git head, this code doesn't work: ------------------------- import std.typecons; struct S { bool opEquals(T)(T a) { return false; } } void main(string[] args) { auto t = tuple(S.init); } ------------------------- RESULT: ------------------------- import\std\typecons.d(432): Error: template main.S.opEquals does not match any function template declaration main.d(5): Error: template main.S.opEquals cannot deduce template function from argument types !()(const(S)) ------------------------- This problem is probably caused by this commit: https://github.com/D-Programming-Language/phobos/commit/3c878f4b90670b46854fc66a09a8f68995fdb4ea This implementation forces opEquals() const on the type that it controls. Add a further condition that is to define the method if needed to constraint-if to avoid it.
Comment #1 by k.hara.pg — 2012-09-18T08:45:51Z
Comment #2 by github-bugzilla — 2012-09-18T09:44:26Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/414ca6ffd211940d55d598e8a751090fb362da4c fix Issue 8686 - Tuple cannot define with type that has only mutable opEquals We cannot show better error message for mismatching tuple lengths, because compiler would *always* try to instantiate const opEquals. I also added tests for exhaustive opEquals signatures - const or mutable, and template or not https://github.com/D-Programming-Language/phobos/commit/7f5d95adf106a2a3cc1a8439b20cdafa5a8688f3 Merge pull request #803 from 9rnsr/fix8686 Issue 8686 and others, Tuple.opEquals and opCmp does not work in some cases