Jump to page: 1 2 3
Thread overview
[Issue 2367] New: Overloading error
Sep 20, 2008
d-bugmail
Sep 20, 2008
Denis Koroskin
re: news/mail -> bugzilla
Sep 21, 2008
Brad Roberts
Re: news/mail -> bugzilla
Sep 20, 2008
d-bugmail
Sep 20, 2008
d-bugmail
Sep 20, 2008
d-bugmail
Sep 30, 2008
d-bugmail
Jun 15, 2011
yebblies
Jun 15, 2011
yebblies
Jun 15, 2011
yebblies
[Issue 2367] Overloading error with string literals
Jun 17, 2011
Don
Jun 29, 2011
yebblies
Sep 10, 2011
yebblies
Oct 09, 2011
Walter Bright
Feb 19, 2012
yebblies
Mar 24, 2012
Kenji Hara
Mar 27, 2012
Walter Bright
September 20, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2367

           Summary: Overloading error
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: andrei@metalanguage.com


The following code does not compile:

struct S {
    void foo(in char[] s) {}
    void foo(in dchar[] s) {}
}

void main(string[] args) {
    S s;
    s.foo("a");
}

The second overload should not even be considered.


-- 

September 20, 2008
On Sat, Sep 20, 2008 at 2:01 PM,  <d-bugmail@puremagic.com> wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=2367
>
>           Summary: Overloading error
>           Product: D
>           Version: unspecified
>          Platform: PC
>        OS/Version: Linux
>            Status: NEW
>          Severity: normal
>          Priority: P2
>         Component: DMD
>        AssignedTo: bugzilla@digitalmars.com
>        ReportedBy: andrei@metalanguage.com
>
>
> The following code does not compile:
>
> struct S {
>    void foo(in char[] s) {}
>    void foo(in dchar[] s) {}
> }
>
> void main(string[] args) {
>    S s;
>    s.foo("a");
> }
>
> The second overload should not even be considered.

"string literals" do not have a type; they are, in some ways, polysemous.  They are considered char[], wchar[], or dchar[] based on where they're used.  If they're used in a situation where it could go either way (such as this overloading case), it's an error.

The solution is simple: affix a 'c', 'w', or 'd' to the end of the string literal to give it an explicit type.
September 20, 2008
Jarrett Billingsley wrote:
> On Sat, Sep 20, 2008 at 2:01 PM,  <d-bugmail@puremagic.com> wrote:
>> http://d.puremagic.com/issues/show_bug.cgi?id=2367
>>
>>           Summary: Overloading error
>>           Product: D
>>           Version: unspecified
>>          Platform: PC
>>        OS/Version: Linux
>>            Status: NEW
>>          Severity: normal
>>          Priority: P2
>>         Component: DMD
>>        AssignedTo: bugzilla@digitalmars.com
>>        ReportedBy: andrei@metalanguage.com
>>
>>
>> The following code does not compile:
>>
>> struct S {
>>    void foo(in char[] s) {}
>>    void foo(in dchar[] s) {}
>> }
>>
>> void main(string[] args) {
>>    S s;
>>    s.foo("a");
>> }
>>
>> The second overload should not even be considered.
> 
> "string literals" do not have a type; they are, in some ways,
> polysemous.  They are considered char[], wchar[], or dchar[] based on
> where they're used.  If they're used in a situation where it could go
> either way (such as this overloading case), it's an error.
> 
> The solution is simple: affix a 'c', 'w', or 'd' to the end of the
> string literal to give it an explicit type.

To facilitate archiving, you may want to post replies to the website instead.

Andrei
September 20, 2008
On Sat, Sep 20, 2008 at 3:10 PM, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
> Jarrett Billingsley wrote:
>>
>> On Sat, Sep 20, 2008 at 2:01 PM,  <d-bugmail@puremagic.com> wrote:
>>>
>>> http://d.puremagic.com/issues/show_bug.cgi?id=2367
>>>
>>>          Summary: Overloading error
>>>          Product: D
>>>          Version: unspecified
>>>         Platform: PC
>>>       OS/Version: Linux
>>>           Status: NEW
>>>         Severity: normal
>>>         Priority: P2
>>>        Component: DMD
>>>       AssignedTo: bugzilla@digitalmars.com
>>>       ReportedBy: andrei@metalanguage.com
>>>
>>>
>>> The following code does not compile:
>>>
>>> struct S {
>>>   void foo(in char[] s) {}
>>>   void foo(in dchar[] s) {}
>>> }
>>>
>>> void main(string[] args) {
>>>   S s;
>>>   s.foo("a");
>>> }
>>>
>>> The second overload should not even be considered.
>>
>> "string literals" do not have a type; they are, in some ways, polysemous.  They are considered char[], wchar[], or dchar[] based on where they're used.  If they're used in a situation where it could go either way (such as this overloading case), it's an error.
>>
>> The solution is simple: affix a 'c', 'w', or 'd' to the end of the string literal to give it an explicit type.
>
> To facilitate archiving, you may want to post replies to the website instead.
>
> Andrei
>

Well that's weird, I could have sworn that replies posted to the NG thread were mirrored on bugzilla.  Maybe it's a bug in the puremagic mailing lists?
September 20, 2008
On Sat, 20 Sep 2008 23:55:38 +0400, Jarrett Billingsley <jarrett.billingsley@gmail.com> wrote:

> On Sat, Sep 20, 2008 at 3:10 PM, Andrei Alexandrescu
> <SeeWebsiteForEmail@erdani.org> wrote:
>> Jarrett Billingsley wrote:
>>>
>>> On Sat, Sep 20, 2008 at 2:01 PM,  <d-bugmail@puremagic.com> wrote:
>>>>
>>>> http://d.puremagic.com/issues/show_bug.cgi?id=2367
>>>>
>>>>          Summary: Overloading error
>>>>          Product: D
>>>>          Version: unspecified
>>>>         Platform: PC
>>>>       OS/Version: Linux
>>>>           Status: NEW
>>>>         Severity: normal
>>>>         Priority: P2
>>>>        Component: DMD
>>>>       AssignedTo: bugzilla@digitalmars.com
>>>>       ReportedBy: andrei@metalanguage.com
>>>>
>>>>
>>>> The following code does not compile:
>>>>
>>>> struct S {
>>>>   void foo(in char[] s) {}
>>>>   void foo(in dchar[] s) {}
>>>> }
>>>>
>>>> void main(string[] args) {
>>>>   S s;
>>>>   s.foo("a");
>>>> }
>>>>
>>>> The second overload should not even be considered.
>>>
>>> "string literals" do not have a type; they are, in some ways,
>>> polysemous.  They are considered char[], wchar[], or dchar[] based on
>>> where they're used.  If they're used in a situation where it could go
>>> either way (such as this overloading case), it's an error.
>>>
>>> The solution is simple: affix a 'c', 'w', or 'd' to the end of the
>>> string literal to give it an explicit type.
>>
>> To facilitate archiving, you may want to post replies to the website
>> instead.
>>
>> Andrei
>>
>
> Well that's weird, I could have sworn that replies posted to the NG
> thread were mirrored on bugzilla.  Maybe it's a bug in the puremagic
> mailing lists?

No, it never used to and I like the way it is!

Sometimes I express my thoughts on the subject here on purpose so that they don't get posted to the bugzilla (because they address some irrelevant topic or loosely related to the original post or not helpful all). This discussion is on of examples :)
September 20, 2008
<d-bugmail@puremagic.com> wrote in message news:bug-2367-3@http.d.puremagic.com/issues/...
> http://d.puremagic.com/issues/show_bug.cgi?id=2367
>
>           Summary: Overloading error
>           Product: D
>           Version: unspecified
>          Platform: PC
>        OS/Version: Linux
>            Status: NEW
>          Severity: normal
>          Priority: P2
>         Component: DMD
>        AssignedTo: bugzilla@digitalmars.com
>        ReportedBy: andrei@metalanguage.com
>
>
> The following code does not compile:
>
> struct S {
>    void foo(in char[] s) {}
>    void foo(in dchar[] s) {}
> }
>
> void main(string[] args) {
>    S s;
>    s.foo("a");
> }
>
> The second overload should not even be considered.

Testing, testing.


September 20, 2008
On Sat, Sep 20, 2008 at 4:35 PM, Denis Koroskin <2korden@gmail.com> wrote:
> On Sat, 20 Sep 2008 23:55:38 +0400, Jarrett Billingsley <jarrett.billingsley@gmail.com> wrote:
>
>> On Sat, Sep 20, 2008 at 3:10 PM, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
>>>
>>> Jarrett Billingsley wrote:
>>>>
>>>> On Sat, Sep 20, 2008 at 2:01 PM,  <d-bugmail@puremagic.com> wrote:
>>>>>
>>>>> http://d.puremagic.com/issues/show_bug.cgi?id=2367
>>>>>
>>>>>         Summary: Overloading error
>>>>>         Product: D
>>>>>         Version: unspecified
>>>>>        Platform: PC
>>>>>      OS/Version: Linux
>>>>>          Status: NEW
>>>>>        Severity: normal
>>>>>        Priority: P2
>>>>>       Component: DMD
>>>>>      AssignedTo: bugzilla@digitalmars.com
>>>>>      ReportedBy: andrei@metalanguage.com
>>>>>
>>>>>
>>>>> The following code does not compile:
>>>>>
>>>>> struct S {
>>>>>  void foo(in char[] s) {}
>>>>>  void foo(in dchar[] s) {}
>>>>> }
>>>>>
>>>>> void main(string[] args) {
>>>>>  S s;
>>>>>  s.foo("a");
>>>>> }
>>>>>
>>>>> The second overload should not even be considered.
>>>>
>>>> "string literals" do not have a type; they are, in some ways, polysemous.  They are considered char[], wchar[], or dchar[] based on where they're used.  If they're used in a situation where it could go either way (such as this overloading case), it's an error.
>>>>
>>>> The solution is simple: affix a 'c', 'w', or 'd' to the end of the string literal to give it an explicit type.
>>>
>>> To facilitate archiving, you may want to post replies to the website instead.
>>>
>>> Andrei
>>>
>>
>> Well that's weird, I could have sworn that replies posted to the NG thread were mirrored on bugzilla.  Maybe it's a bug in the puremagic mailing lists?
>
> No, it never used to and I like the way it is!
>
> Sometimes I express my thoughts on the subject here on purpose so that they don't get posted to the bugzilla (because they address some irrelevant topic or loosely related to the original post or not helpful all). This discussion is on of examples :)
>

Well well.  Color me wrong.
September 20, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2367





------- Comment #1 from jarrett.billingsley@gmail.com  2008-09-20 15:44 -------
"string literals" do not have a type; they are, in some ways, polysemous.  They are considered char[], wchar[], or dchar[] based on where they're used.  If they're used in a situation where it could go either way (such as this overloading case), it's an error.

The solution is simple: affix a 'c', 'w', or 'd' to the end of the string literal to give it an explicit type.


-- 

September 20, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2367





------- Comment #2 from andrei@metalanguage.com  2008-09-20 17:25 -------
Even with polysemy, vocables may have a principal meaning. For example "1" is polysemous because it fits byte, ubyte etc. but absent any constraint it will prefer to be an int.

auto i = 1; // i's type is int

As discussed with Walter, strings are also easy to acquire a principal meaning. One possibility discussed is that strings with only ASCII characters to have invariant(char)[N] as principal type. In fact the N should be dropped too for a number of reasons. So "a" should have principal type invariant(char)[]. (If a constraint is present, no problem.)

The exaggerated ambiguity of string literals has caused much grief to many people, it's about time to fix it.


-- 

September 20, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2367





------- Comment #3 from jarrett.billingsley@gmail.com  2008-09-20 17:49 -------
Amen to dropping the fixed-sizedness of string literals.  I suppose determining the type based on the smallest type that can represent the data without using multibyte encodings is reasonable enough, and you're right, it fits in with the way it works for ints.


-- 

« First   ‹ Prev
1 2 3