www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21787] New: Operator Overload by a Variable not detected


          Issue ID: 21787
           Summary: Operator Overload by a Variable not detected
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: svv1999 hotmail.com

void main(){
  class C{
    bool delegate( int) opIndex;
  auto var= new C;
  assert( var[ 0]); // Error: no `[]` operator overload for type `main.C`

In 20. the specs declare overloads to be rewrites "into calls to specially
named members". In 20.8.1 the specs declare `opIndex` to be such a special
name. No further restriction on the type of that member is given.

The code above declares `opIndex` to be a variable for a delegate, but
compilation is refused.

Therefore either the specs are not complete or the code above should compile:
code should even then compile, when the type of that variable is a class
containing an appropriate overload for a call.

Mar 31 2021