Bug 14262 – [REG] [2.067-b3] Can't use class `this` as ref argument
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-03-09T01:24:00Z
Last change time
2015-06-17T21:01:43Z
Keywords
pull
Assigned to
nobody
Creator
public
Comments
Comment #0 by public — 2015-03-09T01:24:49Z
This code compiles fine in 2.066.1 :
====
class A
{
int opApply(int delegate(ref A obj) dg)
{
return dg(this);
}
}
void main() {}
====
With 2.067-b3 :
./aaa.d(5): Error: delegate dg (ref A obj) is not callable using argument types (A)
It took me some time to realize the error referred to the fact that such call could possibly change original `this` reference which is normally not allowed in D.
While refusing to compile this seems legit and code clearly needs fixing, error message is not helpful at all. It should explain the issue and suggest a fix more clearly.
Comment #1 by bugzilla — 2015-03-09T10:02:59Z
A simpler example:
---
void foo(const ref A a);
class A {
void bar() {
foo(this);
}
}
---
I don't see why this shouldn't compile.
(In reply to Walter Bright from comment #1)
> I don't see why this shouldn't compile.
The reason is issue 13116.
(In reply to Martin Nowak from comment #2)
> This pull caused the regression.
> https://github.com/D-Programming-Language/dmd/pull/3761
So this is an invalid issue.
I opened a changelog PR to explain why the change is introduced.
https://github.com/D-Programming-Language/dlang.org/pull/923
*** This issue has been marked as a duplicate of issue 13934 ***
Comment #5 by github-bugzilla — 2015-03-09T23:48:39Z