Bug 9124 – Object variable of variadic template struct needs explicit "this" in certain situations

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-07T19:36:00Z
Last change time
2012-12-17T08:14:12Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
puneet

Comments

Comment #0 by puneet — 2012-12-07T19:36:22Z
Kindly look at the code pasted below. with the current github dmd snapshot, it gives me an error: Error: this for _val needs to be type Foo not type Foo!(28) It is a corner case. I could not reduce the code further than give below. For example if I replace SIZE with N[0] directly in the declarative for result, the issue disappears. struct Foo (N...) { enum SIZE = N[0]; private int _val; public void opAssign (T) (T other) if (is(T unused == Foo!(_N), _N...)) { _val = other._val; // compile error // this._val = other._val; // explicit this make it work } public auto opUnary (string op) () if (op == "~") { Foo!(SIZE) result = this; return result; } } void main() { Foo!(28) a; Foo!(28) b = ~a; }
Comment #1 by github-bugzilla — 2012-12-11T16:22:31Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f6b421121ff945c08bca5bafd8df07913d64a727 fix Issue 9124 - Object variable of variadic template struct needs explicit "this" in certain situations https://github.com/D-Programming-Language/dmd/commit/8e22c48774d4200c80e5808f5c0658d28a0625fc Merge pull request #1366 from 9rnsr/fix9124 Issue 9124 - Object variable of variadic template struct needs explicit "this" in certain situations
Comment #2 by k.hara.pg — 2012-12-11T17:05:58Z
Comment #3 by puneet — 2012-12-12T09:35:19Z
I am reopening the bug with a different testcase that is still failing with the same error. Please see the comments below in the code to locate the offending line. template Foo (T, U, string OP) { enum N = T.SIZE; alias Foo!(false, true, N) Foo; } struct Foo (bool S, bool L, N...) { enum SIZE = 5; long[1] _a = 0; void someFunction() const { auto data = _a; // Does not compile // auto data = this._a; // <--- Compiles } auto opBinary (string op, T) (T ) { Foo!(typeof(this), T, op) test; } } void main() { auto p = Foo!(false, false, 5)(); auto q = Foo!(false, false, 5)(); p|q; p&q; }
Comment #4 by k.hara.pg — 2012-12-12T18:24:42Z
Thanks for finding another case. My first fix was not sufficient. https://github.com/D-Programming-Language/dmd/pull/1368
Comment #5 by puneet — 2012-12-12T23:02:58Z
(In reply to comment #4) > > https://github.com/D-Programming-Language/dmd/pull/1368 This looks good. I have taken out all the 132 "this" disambiguators that I had put in my code. The code compiles and runs perfectly now. Thanks Kenji. You Rock!
Comment #6 by github-bugzilla — 2012-12-17T02:01:52Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/69307c29749ee45ded4c59e58ff01d94b1fbc7bd 2nd fix for Issue 9124 - Object variable of variadic template struct needs explicit "this" in certain situations https://github.com/D-Programming-Language/dmd/commit/3662698e1d592693d7556741bc6bf95474908e9a Merge pull request #1368 from 9rnsr/fix9124 Issue 9124 & 9143 - manifest constant should be de-symbolize in template argument comparison