Bug 20511 – Can't format JSONValue to OutputRange due to @safe
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-01-16T14:00:51Z
Last change time
2020-01-17T08:03:42Z
Keywords
pull
Assigned to
No Owner
Creator
FeepingCreature
Comments
Comment #0 by default_357-line — 2020-01-16T14:00:51Z
Consider the following code:
---
import std.format : formattedWrite;
import std.json : JSONValue;
import std.range : nullSink, OutputRange, outputRangeObject;
void main()
{
outputRangeObject!(const(char)[])(nullSink)
.formattedWrite!"%s"(JSONValue.init);
}
---
This should compile, but it instead produces an error. This is caused by std.json.toJson being `@safe`.
toJson can not be @safe, because it calls arbitrary output range code.
Comment #1 by dlang-bot — 2020-01-16T15:27:26Z
@FeepingCreature created dlang/phobos pull request #7354 "Fix issue 20511: make toJSON determine safeness based on output range safeness." fixing this issue:
- Fix issue 20511: make toJSON infer safeness based on output range safeness.
https://github.com/dlang/phobos/pull/7354
Comment #2 by dlang-bot — 2020-01-17T08:03:42Z
dlang/phobos pull request #7354 "Fix issue 20511: make toJSON determine safeness based on output range safeness." was merged into stable:
- 3e26069a4f7383e02e12df35f4b92cfa4ac113a4 by Mathis Beer:
Fix issue 20511: make toJSON infer safeness based on output range safeness.
https://github.com/dlang/phobos/pull/7354