Bug 13009 – [REG2.064] inout overload conflicts with non-inout when used via alias this

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-06-30T08:28:11Z
Last change time
2021-10-08T07:02:41Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Vladimir Panteleev
Blocks
12368, 12379

Comments

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 #2 by hsteoh — 2014-08-05T17:21:01Z
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
Comment #8 by monarchdodra — 2014-10-26T17:59:57Z
(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 #9 by k.hara.pg — 2015-02-16T17:39:10Z
Comment #10 by github-bugzilla — 2015-02-21T06:13:35Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/b4f6725e3c94c302d5b161a6d7f8dff271cb8f64 fix Issue 13009 - inout overload conflicts with non-inout when used via alias this https://github.com/D-Programming-Language/dmd/commit/d30acc5d9c4a626711c3462ff3d42b9f105cd169 Merge pull request #4417 from 9rnsr/fix13009 [REG2.064] Issue 13009 - inout overload conflicts with non-inout when used via alias this
Comment #11 by github-bugzilla — 2015-02-21T09:11:44Z
Comment #12 by github-bugzilla — 2015-03-01T01:03:53Z
Commit pushed to 2.067 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a7db6d65db9881b78f8abe4243e4f01a01de61d6 Merge pull request #4417 from 9rnsr/fix13009 [REG2.064] Issue 13009 - inout overload conflicts with non-inout when used via alias this
Comment #13 by github-bugzilla — 2015-03-01T01:46:30Z
Comment #14 by github-bugzilla — 2015-04-11T12:24:47Z
Comment #15 by github-bugzilla — 2015-06-17T21:00:52Z
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/b4f6725e3c94c302d5b161a6d7f8dff271cb8f64 fix Issue 13009 - inout overload conflicts with non-inout when used via alias this https://github.com/D-Programming-Language/dmd/commit/d30acc5d9c4a626711c3462ff3d42b9f105cd169 Merge pull request #4417 from 9rnsr/fix13009
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.
Comment #17 by k.hara.pg — 2015-11-03T02:40:32Z
(In reply to Vladimir Panteleev from comment #16) > (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). https://github.com/D-Programming-Language/dmd/pull/5255
Comment #18 by github-bugzilla — 2015-11-06T16:49:36Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/6115e5ed464f2902d60711c36a179d960abeb09b fix Issue 13009 more There was a function declaration order dependent bug in `overloadModMatch`. https://github.com/D-Programming-Language/dmd/commit/575ac488b5f6e040d14ad490a67ecfe57c17ea0f Merge pull request #5259 from 9rnsr/fix13009 [REG2.064] fix Issue 13009 more
Comment #19 by github-bugzilla — 2016-01-03T14:02:20Z
Comment #20 by nicolas.jinchereau — 2017-01-29T19:32:32Z
Getting this in DMD 2.073.0: struct S { struct Payload { int[] data; } RefCounted!(Payload, RefCountedAutoInitialize.yes) payload; alias X = typeof(payload.data[0]); } int main(string[] argv) { return 0; } main.d(196): Error: std.typecons.RefCounted!(Payload, cast(RefCountedAutoInitialize)1).RefCounted.refCountedPayload called with argument types () matches both: typecons.d(5241): std.typecons.RefCounted!(Payload, cast(RefCountedAutoInitialize)1).RefCounted.refCountedPayload() and: typecons.d(5233): std.typecons.RefCounted!(Payload, cast(RefCountedAutoInitialize)1).RefCounted.refCountedPayload()
Comment #21 by github-bugzilla — 2017-07-19T17:38:35Z
Commits pushed to dmd-cxx at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/b4f6725e3c94c302d5b161a6d7f8dff271cb8f64 fix Issue 13009 - inout overload conflicts with non-inout when used via alias this https://github.com/dlang/dmd/commit/d30acc5d9c4a626711c3462ff3d42b9f105cd169 Merge pull request #4417 from 9rnsr/fix13009
Comment #22 by bugzilla — 2018-12-21T23:51:18Z
(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