[Issue 8316] Regression with template functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jun 29 22:11:37 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8316


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

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


--- Comment #7 from Kenji Hara <k.hara.pg at 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: -------


More information about the Digitalmars-d-bugs mailing list