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
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;
}
(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