[Issue 22792] New: Wrong inference of opApply
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Feb 19 06:03:30 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22792
Issue ID: 22792
Summary: Wrong inference of opApply
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: zan77137 at nifty.com
Why is following code different behavior between int and string?
-----------------
import std;
struct S
{
int opApply(int delegate(ref const(int), ref int) dg)
{ writeln("mutable int"); return 0; }
int opApply(int delegate(ref const(int), ref const(int)) dg) const
{ writeln("const int"); return 0; }
int opApply(int delegate(ref const(int), ref string) dg)
{ writeln("mutable str"); return 0; }
int opApply(int delegate(ref const(int), ref const(string)) dg) const
{ writeln("const str"); return 0; }
}
void main()
{
S s;
foreach (ref const(int) x, ref const(int) y; s) {}
foreach (ref const(int) x, ref const(string) y; s) {}
}
-----------------
rdmd playground.d
const int
mutable str
-----------------
The function on the const one that matches better should be called.
This problem was discovered by investigating the cause of Botan(*) build
failure in 2.099.1-beta.1.
However, the above code shows the same behavior since before 2.098.1.
* https://github.com/etcimon/botan
--
More information about the Digitalmars-d-bugs
mailing list