Bug 10066 – Template opEquals sometimes obstructs struct compilation

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-12T01:12:00Z
Last change time
2013-05-14T12:07:05Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2013-05-12T01:12:14Z
During debug for 10056, I found another bug case. Following code will occur strange errors: ---- test.d(71): Error: static assert "Cannot put a char[] into a Appender!(string)" test.d(39): instantiated from here: put!(Appender!(string), char[]) test.d(30): instantiated from here: Foo!(1) code: ---- void main() { alias Zoo = Foo!(1); Zoo z; } struct Foo(size_t N) { string bar() { Appender!(string) w; char[] buf; put(w, buf); return ""; } public bool opEquals(T)(T other) const // <--- Add const, different from bug 10056 { alias Foo!(typeof(this), T, "CMP") P; return false; } } template Foo(T, U, string OP) { static if (T.ISEMPTY && U.ISEMPTY) enum bool S = false; else enum bool S = false; alias Foo = Foo!(0); } void put(R, E)(ref R r, E e) { static if (is(typeof(r.put(e)))) { r.put(e); } else { static assert(false, "Cannot put a "~E.stringof~" into a "~R.stringof); } } struct Appender(A : T[], T) { private template canPutItem(U) { enum bool canPutItem = is(U : T); } private template canPutRange(R) { enum bool canPutRange = is(typeof(Appender.init.put(R.init[0]))); } void put(U)(U item) if (canPutItem!U) { char[T.sizeof == 1 ? 4 : 2] encoded; put(encoded[]); } void put(R)(R items) if (canPutRange!R) { } } The error occurs in the internal code generation for TypeInfo.equals. It instantiates Foo's opEquals member template function in background, but the instantiation errors are now unexpectedly un-gagged.
Comment #1 by k.hara.pg — 2013-05-12T01:25:04Z
Comment #2 by github-bugzilla — 2013-05-14T12:06:51Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/5a1307007cd033386ec3d31c70118deaaeb7ff51 fix Issue 10066 - Template opEquals sometimes obstructs struct compilation Move __xopEquals generation after struct semantic3 done https://github.com/D-Programming-Language/dmd/commit/ad0679d1a7676f694b016b10ed8ae927c08282ae Merge pull request #2025 from 9rnsr/fix10066 Issue 10066 - Template opEquals sometimes obstructs struct compilation