D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20511 - Can't format JSONValue to OutputRange due to @safe
Summary: Can't format JSONValue to OutputRange due to @safe
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 regression
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-01-16 14:00 UTC by FeepingCreature
Modified: 2020-01-17 08:03 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description FeepingCreature 2020-01-16 14:00:51 UTC
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 Dlang Bot 2020-01-16 15:27:26 UTC
@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 Dlang Bot 2020-01-17 08:03:42 UTC
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