Bug 21806 – Overload selection ignores slice

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-04-07T01:08:02Z
Last change time
2021-04-16T04:19:56Z
Keywords
pull
Assigned to
No Owner
Creator
Temtaime

Comments

Comment #0 by temtaime — 2021-04-07T01:08:02Z
Consider: void main() { ubyte[16] arr; pragma(msg, typeof(arr[])); pragma(msg, typeof(arr[].bar)); arr[].bar.writeln; // 123 } char bar()(in ubyte[] arr) { return 'X'; } int bar(size_t N)(in ubyte[N] arr) { return 123; } Compilation output: ubyte[] int Should be: ubyte[] char
Comment #1 by moonlightsentinel — 2021-04-07T03:20:02Z
Up to 2.065.0: Success with output: ----- ubyte[] char -----
Comment #2 by dkorpel — 2021-04-07T08:49:57Z
This compilation output is correct. https://dlang.org/spec/function.html#function-overloading Both functions have match level 3: match with qualifier conversion. That's because `in` makes the parameter `const`, so `ubyte[]` needs to be converted to `const(ubyte)[]`. Then partial ordering determines `const(ubyte)[16]` to be more specialized than `const(ubyte)[]`, so the fixed size version is chosen.
Comment #3 by temtaime — 2021-04-07T08:55:08Z
A slice is taken from argument, it is not original ubyte[16]. If i create temp variable à-la auto tmp = arr[]; bar(tmp); then correct overload is used
Comment #4 by dlang-bot — 2021-04-07T16:56:58Z
@BorisCarvajal created dlang/dmd pull request #12399 "Fix Issue 21806 - Overload selection ignores slice" fixing this issue: - Fix Issue 21806 - Overload selection ignores slice https://github.com/dlang/dmd/pull/12399
Comment #5 by boris2.9 — 2021-04-07T17:14:06Z
Note that using raw functions: char bar(ubyte[] array); int bar(ubyte[16] array); is also a regression: Up to 2.067.1: Success with output: ----- ubyte[] char ----- Since 2.068.2: Success with output: ----- ubyte[] int -----
Comment #6 by dlang-bot — 2021-04-10T23:26:59Z
dlang/dmd pull request #12399 "Fix Issue 21806 - Overload selection ignores slice" was merged into stable: - 9dabb8f03cdb4e4acacd12449fc5558708e8746a by Boris Carvajal: Fix Issue 21806 - Overload selection ignores slice https://github.com/dlang/dmd/pull/12399
Comment #7 by dlang-bot — 2021-04-16T04:19:56Z
dlang/dmd pull request #12431 "merge stable" was merged into master: - 5bba6357deac1ba8d5994ffeb5c526716e89a274 by Boris Carvajal: Fix Issue 21806 - Overload selection ignores slice https://github.com/dlang/dmd/pull/12431