www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8316] New: Regression with template functions

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8316

           Summary: Regression with template functions
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: meh paranoici.org



The code:
---
import std.stdio;

void lol(string wat) ()
{
    writeln(wat);
}

void lol(string wat) (string omg)
{
    writeln(wat, " ", omg);
}

void main ()
{
    lol!"rulez";
}
---

The error:
---
lol.d(15): Error: template lol.lol matches more than one template declaration,
lol.d(3):lol(string wat) and lol.d(8):lol(string wat)
---

I'm too lazy to find the commit, I'm sure you'll know better than me.

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |INVALID



15:19:52 PDT ---
It does match both. Not sure what you expect it to do.

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


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr gmx.ch



Isn't it a function call where the parens were left out?

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


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PDT ---
 Isn't it a function call where the parens were left out?
It would be if the functions didn't have any parameters, but they both do, so I don't know quite what the compiler thinks that it is. Regardless, lol!"rulez" results in a function named lol which takes a single string argument when there's already such a function (albeit non-templated) which exists. It's clearly a conflict no matter what you're trying to do with it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8316





 Isn't it a function call where the parens were left out?
It would be if the functions didn't have any parameters, but they both do, so I don't know quite what the compiler thinks that it is. Regardless, lol!"rulez" results in a function named lol which takes a single string argument when there's already such a function (albeit non-templated) which exists. It's clearly a conflict no matter what you're trying to do with it.
I think you might have missed the second set of parentheses on the first template function declaration. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8316




Both are template functions.

The first is a template function without arguments, the second has one.

I'm calling the first. It throws a dumb error when it's clear what I want to
do. It's code that worked before. It's a regression.

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




PDT ---
 I think you might have missed the second set of parentheses on the first
template function declaration. Ah, you're right. I did miss those, but it still shouldn't compile, because the compiler doesn't know which template the programmer was trying to instantiate. Did they mean the first one (which would then be callable) or the second (which wouldn't, because it lacks the function arguments that it requires). The template functions don't even exist to be checked for overloading rules until they've been instantiated, so overloading rules have no effect here. Remember that they actually translate to template lol(string wat) { void lol() { writeln(wat); } } template lol(string wat) { void lol(string omg) { writeln(wat, " ", omg); } } So, when you say lol!"rulez", which one is the compiler going to pick? It doesn't know which you mean. The template signatures are identical and have no template constraints to distinguish them. So, you have a conflict. If you did template lol(string wat) { void lol() { writeln(wat); } void lol(string omg) { writeln(wat, " ", omg); } } then it would work (assuming that you didn't compile with -property, since then you'd have to do lol!"rulez"() rather than lol!"rulez", since the lol function isn't a property). But with how they're currently declared, you have a conflict between two templates. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8316


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |




 I think you might have missed the second set of parentheses on the first
template function declaration. Ah, you're right. I did miss those, but it still shouldn't compile, because the compiler doesn't know which template the programmer was trying to instantiate. Did they mean the first one (which would then be callable) or the second (which wouldn't, because it lacks the function arguments that it requires). The template functions don't even exist to be checked for overloading rules until they've been instantiated, so overloading rules have no effect here. Remember that they actually translate to
[snip]
 
 So, when you say lol!"rulez", which one is the compiler going to pick? It
 doesn't know which you mean. The template signatures are identical and have no
 template constraints to distinguish them. So, you have a conflict.
I think it should be compile. In D language, template functions, that is a template contains one function declaration, is specially treated in its call, and it is priority than normal template lookup/instantiation rule. In this case, compiler knows the the two lol's are template functions, so such special rule should be applied. In current dmd without -property switch, lol!"rulez" should be implicitly converted to lol!"rulez"(), and matches to the first declaration of lol. Furthermore says, even if you add property and use -property, following code doesn't work. property void lol(string wat) () { writeln(wat); } property void lol(string wat) (string omg) { writeln(wat, " ", omg); } void main() { lol!"rulez"; // should call the first lol!"rulez" = "xxx"; // should call the second } test.d(13): Error: template test.lol matches more than one template declaration, test.d(3):lol(string wat) and test.d(7):lol(string wat) test.d(14): Error: template test.lol matches more than one template declaration, test.d(3):lol(string wat) and test.d(7):lol(string wat) It seems to me that is definitely correct code, but if we make this issue invalid, such property overloading would also become 'invalid'. I cannot accept it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8316




PDT ---


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


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com
            Summary|Regression with template    |Error with template
                   |functions                   |functions



20:20:16 PST ---
You're going to have to be more specific if this is an actual regression. I've
tested as far as 2.032 and can reproduce the error there.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 12 2013