Bug 21420 – Nullable.get default parameter is not lazy

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-11-24T09:28:19Z
Last change time
2024-12-01T16:38:02Z
Assigned to
No Owner
Creator
FeepingCreature
Moved to GitHub: phobos#9812 →

Comments

Comment #0 by default_357-line — 2020-11-24T09:28:19Z
Nullable.get default parameter should obviously be lazy. Every other default value in the language is lazy. Unfortunately, Nullable's is not. This leads to unnecessary evaluations of values that are never used.
Comment #1 by default_357-line — 2020-11-24T09:42:13Z
Oh, I see. It's an issue with lazy... I've tried to fix this, and it runs into the issue that lazy, being not templated, cannot transfer call site guarantees such as @safe and nothrow into the getter function, hence breaking get()'s annotations of nothrow and @safe in a way that makes it unusable in nothrow/@safe code. And there is not even hope that DIP1033 fixes this, because the knowledge that the expression is @safe/nothrow cannot be transferred in through a function call - because the conversion to delegate happens *after* the template instantiation, and the delegate type is the first place that we could have @safe/nothrow knowledge. Damn...
Comment #2 by robert.schadek — 2024-12-01T16:38:02Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9812 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB