Bug 11915 – Inconsistent overload resolution behaviour between `ref` and `out`

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-01-13T06:51:00Z
Last change time
2015-02-18T03:38:52Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
verylonglogin.reg

Comments

Comment #0 by verylonglogin.reg — 2014-01-13T06:51:08Z
This code illustrates the inconsistency: --- void f(int) { } void f(ref int) { } void g(int) { } void g(out int) { } void main() { const int n = 1; f(n); // ok, selects `void f(int)` g(n); // Error: constant 1 is not an lvalue } --- This is either "accepts-invalid" or "rejects-valid" bug. The issue is segregated from Issue 11857.
Comment #1 by k.hara.pg — 2014-01-13T08:33:06Z
(In reply to comment #0) > This code illustrates the inconsistency: > --- > void f(int) { } > void f(ref int) { } > > void g(int) { } > void g(out int) { } > > void main() > { > const int n = 1; > f(n); // ok, selects `void f(int)` > g(n); // Error: constant 1 is not an lvalue > } > --- > > This is either "accepts-invalid" or "rejects-valid" bug. > > > The issue is segregated from Issue 11857. This is diagnostic bug. With g(n) case, it should provide more better error message, like: Error: out paraemter does not match non-mutable lvalue 'n' of type 'const int'
Comment #2 by verylonglogin.reg — 2014-01-13T09:07:37Z
(In reply to comment #1) > This is diagnostic bug. I still don't understand why does `out` and `ref` behave differently.
Comment #3 by maxim — 2014-01-13T10:25:43Z
(In reply to comment #1) > (In reply to comment #0) > > This code illustrates the inconsistency: > > --- > > void f(int) { } > > void f(ref int) { } > > > > void g(int) { } > > void g(out int) { } > > > > void main() > > { > > const int n = 1; > > f(n); // ok, selects `void f(int)` > > g(n); // Error: constant 1 is not an lvalue > > } > > --- > > > > This is either "accepts-invalid" or "rejects-valid" bug. > > > > > > The issue is segregated from Issue 11857. > > This is diagnostic bug. With g(n) case, it should provide more better error > message, like: > > Error: out paraemter does not match non-mutable lvalue 'n' of type 'const int' Why? Either both should be rejected because lvalue arguements are unsuccessfuly matched to lvalue parameters, or should be both matched to (int) version because compiler is not stupid to do what is described above.
Comment #4 by k.hara.pg — 2014-10-26T04:01:07Z
(In reply to Denis Shelomovskij from comment #0) > This is either "accepts-invalid" or "rejects-valid" bug. OK, finally I changed my mind. In that case g(n) should match to non-out parameter. https://github.com/D-Programming-Language/dmd/pull/4091
Comment #5 by github-bugzilla — 2014-10-26T08:51:32Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f536d3f46da72ece838caa6d0eb82e051239b288 fix Issue 11915 - Inconsistent overload resolution behaviour between `ref` and `out` https://github.com/D-Programming-Language/dmd/commit/c6289aaaed66f86de0950954c953f45b0f4f342d Merge pull request #4091 from 9rnsr/fix12447 Issue 12447 & 11915 & 11916 - fix overload resolution issue around IFTI and out parameter
Comment #6 by github-bugzilla — 2015-02-18T03:38:52Z
Commits pushed to 2.067 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f536d3f46da72ece838caa6d0eb82e051239b288 fix Issue 11915 - Inconsistent overload resolution behaviour between `ref` and `out` https://github.com/D-Programming-Language/dmd/commit/c6289aaaed66f86de0950954c953f45b0f4f342d Merge pull request #4091 from 9rnsr/fix12447