Bug 21180 – Wrong selection of opEquals overload in classes

Status
NEW
Severity
blocker
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-08-20T20:16:24Z
Last change time
2024-12-07T13:40:37Z
Assigned to
No Owner
Creator
alexandru.ermicioi
Moved to GitHub: dmd#17190 →

Comments

Comment #0 by alexandru.ermicioi — 2020-08-20T20:16:24Z
Test case: ------------- import std; class Silly { bool opEquals(const Silly silly) const @safe { return silly is this; } alias opEquals = Object.opEquals; } bool comp(T)() @safe { return new T() == new T(); } void main() { comp!Silly.writeln; comp!(const Silly).writeln; comp!(immutable Silly).writeln; } ------------- Expected behavior: For "==" overload to be selected most narrow solution which is "bool opEquals(const Silly silly) const @safe" and not "Object.opEquals". To note here: If instead of ==, opEquals is directly called, overload is properly resolved to most narrow solution. Error: ------------- onlineapp.d(12): Error: @safe function onlineapp.comp!(Silly).comp cannot call @system function object.opEquals /dlang/dmd/linux/bin64/../../src/druntime/import/object.d(162): object.opEquals is declared here onlineapp.d(17): Error: template instance onlineapp.comp!(Silly) error instantiating onlineapp.d(12): Error: @safe function onlineapp.comp!(const(Silly)).comp cannot call @system function object.opEquals /dlang/dmd/linux/bin64/../../src/druntime/import/object.d(162): object.opEquals is declared here onlineapp.d(18): Error: template instance onlineapp.comp!(const(Silly)) error instantiating onlineapp.d(12): Error: @safe function onlineapp.comp!(immutable(Silly)).comp cannot call @system function object.opEquals /dlang/dmd/linux/bin64/../../src/druntime/import/object.d(162): object.opEquals is declared here onlineapp.d(19): Error: template instance onlineapp.comp!(immutable(Silly)) error instantiating -------------
Comment #1 by robert.schadek — 2024-12-07T13:40:37Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17190 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB