www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17766] New: Wrong choice of generic mutable/const/immutable

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

          Issue ID: 17766
           Summary: Wrong choice of generic mutable/const/immutable
                    methods
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ilyayaroshenko gmail.com

static struct Foo()
    {
        char opIndex(Indexes...)(Indexes indexes) immutable
        {
            return 'i';
        }

        char opIndex()() const
        {
            return 'c';
        }

        char opIndex(Indexes...)(Indexes indexes)
        {
            return 'm';
        }
    }
    pragma(msg, Foo!()()[]);
    pragma(msg, (cast(const) Foo!()())[]);
    pragma(msg, (cast(immutable) Foo!()())[]);

Prints
'c'
'c'
'c'

But shuold be

'm'
'c'
'i'

Type qualifier should have priority.

--
Aug 19 2017