Fix compile error caused by customized mapping of enums during JSONSerialization #78009
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
In
JSONSerialization.h
, if I map an enum into json by implementingScalarBitSetTraits::bitset()
method, the result of the logical operation of two enums (which is int) will be assigned to an enum, which causes the compile error.The changes are:
static_cast<T>
to convert the result in allbitset
related methods.Rationale
I'm trying to extract the Swift and Objective-C AST into separate JSON files. During the extraction, I take advantage of swift's JSONSerialization tools to perform the mapping from AST nodes to json objects. However, some compile errors occur during the process. The following demo is a simplified version of what I'm doing:
The above demo is built as a swift tool (the detail is omitted). When I run the demo, the compiler complains that:
It turns out that
Decl::ObjCDeclQualifier
is enum but the result ofVal | ConstVal
is int. That seems to be the root cause of the error. Then I modify the source code ofJSONSerialization.h
by statically cast the result:After that, it works and the json serialization results are correct.