www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16328] New: shared-unshared method collision for templated

https://issues.dlang.org/show_bug.cgi?id=16328

          Issue ID: 16328
           Summary: shared-unshared method collision for templated methods
           Product: D
           Version: D2
          Hardware: x86_64
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: hbaelx hotmail.com

The following program perfectly reproduces this error:
-----

import std.stdio;

struct Foo
{
    void ping()
    {
        writeln("Regular ping");
    }

    void ping() shared
    {
        writefln("Shared ping");
    }

    void pang(T)()
    {
        writeln("Regular pang with " ~ T.stringof);
    }

    void pang(T)() shared
    {
        writeln("Shared pang with " ~ T.stringof);
    }

    void bug()
    {
        ping(); // OK, calls regular ping()
        pang!int(); /*  both.d(28): Error: both.Foo.pang called with argument
types () matches both:
                        both.d(15):     both.Foo.pang!int.pang()
                        and:
                        both.d(20):     both.Foo.pang!int.pang() */

        this.pang!int(); // OK, workaround to call regular pang!int()
    }

    void bug() shared
    {
        ping(); // OK, calls shared ping();
        pang!int(); /*  Error: both.Foo.pang called with argument types ()
matches both:
                        both.d(15):     both.Foo.pang!int.pang()
                        and:
                        both.d(20):     both.Foo.pang!int.pang() */

        this.pang!int(); // OK, workaround to call shared pang!int()
    }
}

void main()
{
    auto a = Foo();
    a.bug();

    auto b = shared Foo();
    b.bug();
}

------

Apparently, the compiler cannot tell between shared and non-shared methods when
these are templated. Happens for both struct and classes.

--
Jul 27 2016