Bug 21787 – Operator Overload by a Variable not detected

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-04-01T02:22:11Z
Last change time
2024-12-13T19:15:41Z
Assigned to
No Owner
Creator
Manfred Nowak
Moved to GitHub: dmd#19902 →

Comments

Comment #0 by svv1999 — 2021-04-01T02:22:11Z
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.
Comment #1 by svv1999 — 2021-04-01T10:57:20Z
Specs.20.8|1 require `opIndex` to be a method. Therefore this is not a bug, but an enhancement. Although that requirement can be satisfied by declaring class C{ bool delegate( int) opIndexVar; bool opIndex( int arg){ return opIndexVar( arg); } } the result would be an additional call unless the machine code generator optimizes that call away.
Comment #2 by robert.schadek — 2024-12-13T19:15:41Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19902 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB