Comment #0 by dlang-bugzilla — 2014-06-30T08:28:11Z
From https://github.com/D-Programming-Language/phobos/pull/2011#issuecomment-38431708:
///////// test.d ////////
struct T
{
void put(char c) {}
}
struct S
{
T t;
@property
T getT()
{
return t;
}
@property
inout(T) getT() inout
{
return t;
}
alias getT this;
}
alias Sput = S.put;
/////////////////////////
This produces the errors:
test.d(25,1): Error: test.S.getT called with argument types () matches both:
test.d(11,7): test.S.getT()
and:
test.d(17,14): test.S.getT()
If this is not a compiler bug, then the implementation of RefCounted needs to be changed to account for this behavior.
Comment #1 by dfj1esp02 — 2014-07-16T13:41:24Z
The struct literal should be probably mutable, so mutable overload (exact mutability match) should be preferred. If its mutability can't be affected by the method.
Comment #3 by dlang-bugzilla — 2014-08-27T07:21:59Z
Today I stumbled upon this issue again, and discovered it's a regression.
One manifestation of this issue is that it prevents using static methods of RefCounted's wrapped class.
Example:
////////// test.d /////////
import std.typecons;
struct SImpl
{
static void open() {}
}
alias S = RefCounted!SImpl;
void main()
{
S.open();
}
///////////////////////////
Works in DMD 2.063. In 2.064.2 and newer:
test.d(14): Error: std.typecons.RefCounted!(SImpl, cast(RefCountedAutoInitialize)1).RefCounted.refCountedPayload called with argument types () matches both:
C:\...\std\typecons.d(3893): std.typecons.RefCounted!(SImpl, cast(RefCountedAutoInitialize)1).RefCounted.refCountedPayload()
and:
C:\...\std\typecons.d(3885): std.typecons.RefCounted!(SImpl, cast(RefCountedAutoInitialize)1).RefCounted.refCountedPayload()
Introduced in https://github.com/D-Programming-Language/dmd/pull/2047
Comment #4 by code — 2014-10-06T23:19:52Z
Why do you need both a mutable and an inout version of the same function?
Comment #5 by dlang-bugzilla — 2014-10-06T23:21:20Z
I don't, RefCounted does.
Comment #6 by code — 2014-10-16T07:46:34Z
(In reply to Vladimir Panteleev from comment #5)
> I don't, RefCounted does.
And why? Shouldn't inout just do the trick?
Comment #7 by dlang-bugzilla — 2014-10-19T19:53:16Z
(In reply to Martin Nowak from comment #6)
> (In reply to Vladimir Panteleev from comment #5)
> > I don't, RefCounted does.
>
> And why? Shouldn't inout just do the trick?
Yes and no. There shouldn't be overloads. The reason there is a (conditional) mutable version is so that "autoInitialize.Yes" can mutate to create an instance.
That said, I think that when you have "autoInitialize.Yes", there should be no inout version at all, since inout *can't* mutate the RefCounted to do said initialization.
The conclusion is that while both mutable/inout version are needed, both should be mutually exclusive, and noone should ever see it overloaded.
(In reply to Vladimir Panteleev from comment #7)
> Probably. monarchdodra is planning to fix this:
> https://github.com/D-Programming-Language/phobos/pull/2011#issuecomment-
> 55572141
Not anymore. No time.
Comment #16 by dlang-bugzilla — 2015-10-30T15:35:08Z
(In reply to Kenji Hara from comment #9)
> https://github.com/D-Programming-Language/dmd/pull/4417
Sorry, but that fix is incomplete and doesn't actually fix the real-life problem (comment #3).
Updated reduced test case:
///////// test.d ////////
struct T
{
void put(char c) {}
}
struct S
{
T t;
static if (true)
{
T getT()
{
return t;
}
}
inout(T) getT() inout
{
return t;
}
alias getT this;
}
alias Sput = S.put;
/////////////////////////
Note the "static if (true)". Without it compilation works.
(In reply to bitwise from comment #20)
> Getting this in DMD 2.073.0:
> [...]
Please use complete examples. Guessing at what is missing may miss what is actually wrong, and in any case consumes much extra time.
Comment #23 by nicolas.jinchereau — 2018-12-22T00:35:14Z
(In reply to Walter Bright from comment #22)
> (In reply to bitwise from comment #20)
> > Getting this in DMD 2.073.0:
> > [...]
>
> Please use complete examples. Guessing at what is missing may miss what is
> actually wrong, and in any case consumes much extra time.
Sorry, do you mean the import statements?
I added them and tried DMD 2.083.1, but I'm getting a different error:
```
import std.typecons;
struct S {
struct Payload {
int[] data;
}
RefCounted!(Payload, RefCountedAutoInitialize.yes) payload;
alias X = typeof(payload.data[0]);
void foo() {
payload.data[0] = 0;
}
}
int main(string[] argv) {
return 0;
}
```
> Error: no property data for type RefCounted!(Payload, cast(RefCountedAutoInitialize)1)
But alias this is there:
https://github.com/dlang/phobos/blob/e87b111162df48db747d535715817a37cefba6b1/std/typecons.d#L6308
It's been a while since I've used D, but as far as I can tell that code should compile. The presence of S.foo does not affect compilation either.
Comment #24 by bugzilla — 2020-02-12T03:51:39Z
If you can get a test case without imports that is complete, that would be appreciated.
Comment #25 by dlang-bugzilla — 2020-02-12T04:03:42Z
(In reply to Walter Bright from comment #24)
> If you can get a test case without imports that is complete, that would be
> appreciated.
///////////////// test.d /////////////////
struct RefCounted(T)
{
ref T refCountedPayload()
{
assert(false);
}
ref inout(T) refCountedPayload() inout
{
assert(false);
}
alias refCountedPayload this;
}
struct S
{
struct Payload
{
int[] data;
}
RefCounted!Payload payload;
alias X = typeof(payload.data[0]);
void foo()
{
payload.data[0] = 0;
}
}
int main(string[] argv)
{
return 0;
}
//////////////////////////////////////////
It looks like the problem is specific to typeof this time.
Comment #26 by dlang-bot — 2021-10-01T17:14:09Z
@BorisCarvajal created dlang/dmd pull request #13118 "Fix Issue 13009 - [REG2.064] inout overload conflicts with non-inout when used via alias this" fixing this issue:
- Fix Issue 13009 - [REG2.064] inout overload conflicts with non-inout when used via alias this
https://github.com/dlang/dmd/pull/13118
Comment #27 by dlang-bot — 2021-10-05T09:29:13Z
dlang/dmd pull request #13118 "Fix Issue 13009 - [REG2.064] inout overload conflicts with non-inout when used via alias this" was merged into stable:
- 08b546fa3463484a71fee7fb26d3ece86c87860a by Boris Carvajal:
Fix Issue 13009 - [REG2.064] inout overload conflicts with non-inout when used via alias this
https://github.com/dlang/dmd/pull/13118
Comment #28 by dlang-bot — 2021-10-08T07:02:41Z
dlang/dmd pull request #13140 "merge stable" was merged into master:
- 061ab3b618c47e0181bf6836afc000ffa366e5a5 by Boris Carvajal:
Fix Issue 13009 - [REG2.064] inout overload conflicts with non-inout when used via alias this (#13118)
https://github.com/dlang/dmd/pull/13140