[Issue 21285] Delegate covariance broken between 2.092 and 2.094 (git master).
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Nov 23 19:45:33 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21285
hsteoh at quickfur.ath.cx changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
Status|RESOLVED |REOPENED
Resolution|FIXED |---
--- Comment #5 from hsteoh at quickfur.ath.cx ---
The problem has not been completely fixed. Just a slight refactoring and it
fails again:
Code:
--------
int f(string s) { throw new Exception(""); }
void main()
{
string path;
int bank, preset;
void delegate(string value)[string] aa = [
"path": (string arg) {
path = arg;
},
"bank": (string arg) {
bank = f(arg);
},
"preset": (string arg) {
preset = f(arg);
},
];
}
--------
Compiler output:
--------
test.d(7): Error: cannot implicitly convert expression __lambda1 of type void
delegate(string arg) pure nothrow @nogc @safe to void delegate(string arg)
@system
--------
Oddly enough, replacing the `preset` line with `preset = 1;` makes the problem
go away. Somehow the number of elements in the AA initializer changes compiler
behaviour.
Expected behaviour: `pure nothrow @nogc @safe` ought to be covariant with
`@system`. And this covariance should not vary with unrelated factors such as
the number of elements in the AA initializer.
--
More information about the Digitalmars-d-bugs
mailing list