www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2367] New: Overloading error

reply d-bugmail puremagic.com writes:
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.


-- 
Sep 20 2008
next sibling parent reply "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
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.
Sep 20 2008
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
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
Sep 20 2008
parent Brad Roberts <braddr puremagic.com> writes:
 To facilitate archiving, you may want to post replies to the website
 instead.

 Andrei

thread were mirrored on bugzilla. Maybe it's a bug in the puremagic mailing lists?

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.

It's supposed to. If that's stopped working, I'll fix it. It's extremely handy.
Sep 20 2008
prev sibling next sibling parent "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
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?
Sep 20 2008
prev sibling next sibling parent "Denis Koroskin" <2korden gmail.com> writes:
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 :)
Sep 20 2008
prev sibling next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
<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.
Sep 20 2008
prev sibling next sibling parent "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
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.
Sep 20 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
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.


-- 
Sep 20 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
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.


-- 
Sep 20 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
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.


-- 
Sep 20 2008
prev sibling next sibling parent "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Sat, Sep 20, 2008 at 11:00 PM, Brad Roberts <braddr puremagic.com> wrote:
 To facilitate archiving, you may want to post replies to the website
 instead.

 Andrei

thread were mirrored on bugzilla. Maybe it's a bug in the puremagic mailing lists?

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.

It's supposed to. If that's stopped working, I'll fix it. It's extremely handy.

I knew it!
Sep 20 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2367





------- Comment #4 from terranium yandex.ru  2008-09-30 03:09 -------
(In reply to comment #2)
 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.

--
Sep 30 2008