Skip to content

fix(caster): deep-copy library value types ahead of scalar/string dispatch#1

Merged
BombaxCeiba merged 1 commit into
mainfrom
fix/value-deep-copy-cast
Jul 2, 2026
Merged

fix(caster): deep-copy library value types ahead of scalar/string dispatch#1
BombaxCeiba merged 1 commit into
mainfrom
fix/value-deep-copy-cast

Conversation

@BombaxCeiba

@BombaxCeiba BombaxCeiba commented Jul 2, 2026

Copy link
Copy Markdown
Owner

What

default_caster<yyjson::value> fell into the scalar string branch because std::constructible_from<yyjson::value, std::string_view> spuriously evaluates to true (on both MSVC and clang — caused by constructors inherited through using base::base), throwing "is not constructible from JSON string" for object/array input. This breaks any DTO that reflects a yyjson::value field under default_caster (downstream symptom: DAS MaaExecutionPlanDto::tasks[].pipeline_override on MSVC).

Fix

  1. Deep-copy branch ranked ahead of scalar/string dispatch (first if constexpr in default_caster::from_json): for the library's own value-owning types, return T(json) — uses the existing implicit converting ctor (doc_.copy_value) to clone the subtree into a fresh self-owned value (value-semantic, like reader::value). default_initializable<T> excludes non-owning _ref views.
  2. Tighten string-branch SFINAE (3 sites) with && !writer::detail::base_of_value<T> — belt-and-suspenders.
  3. New regression test test/test_value_cast.cpp.

Verification

  • Local clang (mingw): ctest 63/63, 0 fail. Includes test.cpp (1000+ static_asserts compiling clean), test_msvc_regression, test_aggregate_fallback (string-cast guard), test_value_cast.
  • Downstream DAS: DasMaaPiRuntime 20/20 on MSVC (was 13 fail); full DasMaaPiTest 66/0 on mingw.
  • This PR's CI: MSVC matrix (cl v143/v145 + clang-cl) + Ubuntu (gcc-12..15, clang-16..18).

Tracking: DAS-84.

…patch

default_caster<yyjson::value> fell into the scalar string branch because
constructible_from<value, string_view> spuriously evaluated to true on both
MSVC and clang (constructors inherited via `using base::base`), throwing
"is not constructible from JSON string" for object/array input. This broke
DTOs that reflect a yyjson::value field under default_caster (e.g. DAS
MaaExecutionPlanDto::tasks[].pipeline_override) on MSVC, and direct
cast<yyjson::value> on every compiler.

- default_caster: add a deep-copy branch for library value-owning types
  (default_initializable<T> && base_of_value<T> && requires{T(json)}) ranked
  AHEAD of the scalar/string branches; returns T(json), which uses the
  existing implicit converting ctor (doc_.copy_value) to clone the subtree
  into a fresh self-owned value. Excludes non-owning _ref views.
- Tighten the three string-branch SFINAEs (4406/4412/4418) with
  `&& !base_of_value<T>` as belt-and-suspenders.
- test_value_cast.cpp: regression covering direct cast<value>(object/number),
  aggregate DTO with value field, and that string cast is unaffected.

Verified: DAS DasMaaPiRuntime 20/20 on MSVC (was 13 fail), DAS full
DasMaaPiTest 66 pass/0 fail on mingw; lib ctest 63/63 on clang (mingw),
including test.cpp 1000+ static_asserts compiling clean.

修复(转换器): 库 value 类型在 scalar/字符串派发之前深拷贝

constructible_from<value,string_view> 因继承构造函数在 MSVC/clang 上误报为
true,value 误入字符串分支对 object 输入抛 "not constructible from JSON string",
导致带 yyjson::value 字段的 DTO 在 default_caster 反射下于 MSVC 失败。

GLM-5 代表 Dusk 创建了这个提交
@BombaxCeiba
BombaxCeiba merged commit 64b6c9c into main Jul 2, 2026
26 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant