View mode: basic / threaded / horizontal-split · Log in · Help
June 29, 2012
[Issue 8316] New: Regression with template functions
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


--- Comment #0 from meh. <meh@paranoici.org> 2012-06-29 09:53:16 PDT ---
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: -------
June 29, 2012
[Issue 8316] Regression with template functions
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


--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> 2012-06-29 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: -------
June 29, 2012
[Issue 8316] Regression with template functions
http://d.puremagic.com/issues/show_bug.cgi?id=8316


timon.gehr@gmx.ch changed:

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


--- Comment #2 from timon.gehr@gmx.ch 2012-06-29 16:25:29 PDT ---
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: -------
June 29, 2012
[Issue 8316] Regression with template functions
http://d.puremagic.com/issues/show_bug.cgi?id=8316


Jonathan M Davis <jmdavisProg@gmx.com> changed:

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


--- Comment #3 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-06-29 16:45:53 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: -------
June 29, 2012
[Issue 8316] Regression with template functions
http://d.puremagic.com/issues/show_bug.cgi?id=8316



--- Comment #4 from timon.gehr@gmx.ch 2012-06-29 16:47:38 PDT ---
(In reply to comment #3)
> > 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: -------
June 29, 2012
[Issue 8316] Regression with template functions
http://d.puremagic.com/issues/show_bug.cgi?id=8316



--- Comment #5 from meh. <meh@paranoici.org> 2012-06-29 16:50:31 PDT ---
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: -------
June 29, 2012
[Issue 8316] Regression with template functions
http://d.puremagic.com/issues/show_bug.cgi?id=8316



--- Comment #6 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-06-29 17:01:10 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: -------
June 30, 2012
[Issue 8316] Regression with template functions
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                     |


--- Comment #7 from Kenji Hara <k.hara.pg@gmail.com> 2012-06-29 22:14:10 PDT ---
(In reply to comment #6)
> > 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: -------
July 10, 2012
[Issue 8316] Regression with template functions
http://d.puremagic.com/issues/show_bug.cgi?id=8316



--- Comment #8 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-07-10 14:10:53 PDT ---
See also bug# 8373

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 13, 2013
[Issue 8316] Error with template functions
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


--- Comment #9 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-12 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: -------
Top | Discussion index | About this forum | D home