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.
Comment #1 by bugzilla — 2012-06-29T15:19:52Z
It does match both. Not sure what you expect it to do.
Comment #2 by timon.gehr — 2012-06-29T16:25:29Z
Isn't it a function call where the parens were left out?
Comment #3 by issues.dlang — 2012-06-29T16:45:53Z
> 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.
Comment #4 by timon.gehr — 2012-06-29T16:47:38Z
(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.
Comment #5 by meh — 2012-06-29T16:50:31Z
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.
Comment #6 by issues.dlang — 2012-06-29T17:01:10Z
> 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.
Comment #7 by k.hara.pg — 2012-06-29T22:14:10Z
(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.
Comment #8 by issues.dlang — 2012-07-10T14:10:53Z
See also bug# 8373
Comment #9 by andrej.mitrovich — 2013-01-12T20:20:16Z
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.