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