Bug 22119 – [Functions] Function Overloading clarity for int[] and strings

Status
NEW
Severity
enhancement
Priority
P4
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-07-12T18:15:40Z
Last change time
2024-12-15T15:27:05Z
Assigned to
No Owner
Creator
crazymonkyyy
Moved to GitHub: dlang.org#3989 →

Attachments

IDFilenameSummaryContent-TypeSize
1824schdatatyps.dcode with confususion, line 50text/x-dsrc1617

Comments

Comment #0 by crazymonkyyy — 2021-07-12T18:15:40Z
Created attachment 1824 code with confususion, line 50 import std; struct bar{ int i; } struct foo{ bar i; alias i this; } void foobar(bar[] yo){ //void foobar(T:bar[])(T yo){ "bar[]".writeln; } void foobar(T:foo)(T[3] t){ "foo[3]".writeln;} unittest{ foobar([foo(),foo(),foo()]); } --- I would suggest throwing in a note that says something like "int[3] matches to string before T[3] this can be fixed by redefining string function to '(T:string)(T s)'"
Comment #1 by maxhaton — 2021-07-20T00:05:25Z
Is this not implied by the existing overload matching rules?
Comment #2 by crazymonkyyy — 2021-07-30T20:43:56Z
(In reply to mhh from comment #1) > Is this not implied by the existing overload matching rules? You were part of the conversation on discord and didnt see it either? its implied if I understand the rules, but unclear. the implicit int to char and char[] being close enough to strings was very surprising given a foo(intT)(intT[3]) and foo(string) overloads
Comment #3 by dfj1esp02 — 2021-08-02T12:26:27Z
A more meaningful example: --- struct Address { this(in char[] host, int port){} this(ubyte[4] ip, int port){} } auto addr=Address([127,0,0,1],80); --- I wanted overloads for host name and ip address, but they are ambiguous.
Comment #4 by robert.schadek — 2024-12-15T15:27:05Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dlang.org/issues/3989 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB