Thread overview
[Issue 5709] New: template instantiation fails with extra non-mutable class parameter
Mar 06, 2011
Jonathan M Davis
Apr 23, 2012
SomeDude
Apr 24, 2012
Jonathan M Davis
March 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5709

           Summary: template instantiation fails with extra non-mutable
                    class parameter
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: jmdavisProg@gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg@gmx.com> 2011-03-05 18:35:26 PST ---
This program fails to compile

import std.traits;

class C
{
}

void func1(S)(in S str, immutable C a = null)
    if(isSomeString!S)
{
    func2(str, a);
}

void func2(S)(in S str, immutable C a = null)
    if(isSomeString!S)
{
}

void main()
{
    func1("hello world");
    func2("hello world");
}

giving this error:

q.d(10): Error: template q.func2(S) if (isSomeString!(S)) does not match any
function template declaration
q.d(10): Error: template q.func2(S) if (isSomeString!(S)) cannot deduce
template function from argument types
!()(const(immutable(char)[]),immutable(C))
q.d(20): Error: template instance q.func1!(string) error instantiating

Removing the template constraints has no effect. Thus far, anything that I change immutable C a to anything other than a const C, _does_ compile, but it fails to compile as long as it's const or immutable. The fact that it's a default parameter seems to have no effect. If pass it a new C() instead of null, that has no effect. If I change the func2 call in func1 to func2!S, then it compiles just fine. But for some reason, when the second class parameter is there and it's not mutable, the template instantiation fails to determine the correct type of S for the inner instantiation, and you're forced to tell it.

So, this bug is just plain weird, and it _can_ be gotten around, but it's _definitely_ a bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5709


SomeDude <lovelydear@mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear@mailmetrash.com


--- Comment #1 from SomeDude <lovelydear@mailmetrash.com> 2012-04-23 00:10:51 PDT ---
Compiles and runs with 2.059 Win32

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 24, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5709


Jonathan M Davis <jmdavisProg@gmx.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: -------