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 reply "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
parent reply "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
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 Brad Roberts <braddr puremagic.com> writes:
 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.
It's supposed to. If that's stopped working, I'll fix it. It's extremely handy.
Sep 20 2008
prev 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
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.
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 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 d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2367






"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






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






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 d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2367







 One possibility discussed is that strings with only ASCII characters to have
 invariant(char)[N] as principal type.
What's up with ASCII? char in D is utf byte.
 In fact the N should be dropped too for a number of reasons.
ololo templates? --
Sep 30 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2367


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com



From Andrei's comment on bug 2606

void f(const(char)[] s) {}
void f(const(dchar)[] s) {}

void main()
{
    f("abc");
    auto a = "abc";
    f(a);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 15 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2367




*** Issue 2606 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 15 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2367


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dfj1esp02 sneakemail.com



*** Issue 4592 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 15 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2367


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ellery-newcomer utulsa.edu



*** Issue 4353 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 17 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2367


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
           Platform|x86                         |All
            Version|unspecified                 |D2
         OS/Version|Linux                       |All



https://github.com/D-Programming-Language/dmd/pull/176

This issue also applies to 'null' literals.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 29 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2367


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zeljko.grk gmail.com



*** Issue 6639 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 10 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2367


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com
           Severity|normal                      |enhancement


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2367


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|pull                        |
         AssignedTo|nobody puremagic.com        |bugzilla digitalmars.com



The pull is still valid (if in need of a rebase) but the solution needs a
decision from Walter on how the match level problem is going to be solved in
the future.

See issue 4953 for another example.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2367


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull



---
https://github.com/D-Programming-Language/dmd/pull/834

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2367




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/58f284e625cb6591f476c1fbcad38a6dc66ca039


Issue 2367 - Overloading error with string literals

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 26 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2367


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 26 2012