-
-
Notifications
You must be signed in to change notification settings - Fork 744
replace delegate with simple nested function #8530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1537,19 +1537,15 @@ if (isOutputRange!(Out,char)) | |
| toStringImpl!char(str); | ||
| } | ||
|
|
||
| // recursive @safe inference is broken here | ||
| // workaround: if json.put is @safe, we should be too, | ||
| // so annotate the recursion as @safe manually | ||
| static if (isSafe!({ json.put(""); })) | ||
| { | ||
| void delegate(ref const JSONValue, ulong) @safe toValue; | ||
| } | ||
| else | ||
| { | ||
| void delegate(ref const JSONValue, ulong) @system toValue; | ||
| } | ||
| /* make the function infoer @system when json.put() is @system | ||
| */ | ||
| if (0) | ||
| json.put(' '); | ||
|
|
||
| void toValueImpl(ref const JSONValue value, ulong indentLevel) | ||
| /* Mark as @trusted because json.put() may be @system. This has difficulty | ||
| * inferring @safe because it is recursive. | ||
| */ | ||
| void toValueImpl(ref const JSONValue value, ulong indentLevel) @trusted | ||
| { | ||
| void putTabs(ulong additionalIndent = 0) | ||
| { | ||
|
|
@@ -1594,7 +1590,7 @@ if (isOutputRange!(Out,char)) | |
| json.put(':'); | ||
| if (pretty) | ||
| json.put(' '); | ||
| toValue(member, indentLevel + 1); | ||
| toValueImpl(member, indentLevel + 1); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1631,7 +1627,7 @@ if (isOutputRange!(Out,char)) | |
| if (i) | ||
| putCharAndEOL(','); | ||
| putTabs(1); | ||
| toValue(el, indentLevel + 1); | ||
| toValueImpl(el, indentLevel + 1); | ||
| } | ||
| putEOL(); | ||
| putTabs(); | ||
|
|
@@ -1710,9 +1706,7 @@ if (isOutputRange!(Out,char)) | |
| } | ||
| } | ||
|
|
||
| toValue = &toValueImpl; | ||
|
|
||
| toValue(root, 0); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To prevent adding a safety hole in // Make the function infer `@system` when `json.put` is `@system`
if (0) json.put(' ');There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how this improves anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surely this shouldn't compile: struct Sink {
void put(char c) @system
{
*(cast(int*) 0xDEADBEEF) = 0;
}
}
void main() @safe
{
Sink s;
auto jv = JSONValue("x");
toJson(s, jv);
}There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A function that takes a template There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All right, but I dislike doing kludges like this. At least it's not as bad as the delegate kludge being replaced. |
||
| toValueImpl(root, 0); | ||
| } | ||
|
|
||
| // https://issues.dlang.org/show_bug.cgi?id=12897 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.