| Property | Value |
|---|---|
| Category | Usage (JustDummies.Usage) |
| Severity | 🟠 Warning |
| Enabled by default | Yes |
Any.OneOf draws one value from a pool of values. Handed generators, it infers the builder type as the pool’s element type: the pool holds recipes, and drawing from it yields a recipe rather than a value — which then flows on into the object and text positions JD005 and JD011 report.
What makes this a trap rather than an obvious slip is that the surface is inconsistent about it. Any.OneOf(Any.Int32(), Any.Int64()) fails type inference and the compiler stops you; Any.OneOf(Any.Int32(), Any.Int32()) binds cleanly and says nothing.
Noncompliant
IAny<AnyInt32> pool = Any.OneOf(Any.Int32().Positive(), Any.Int32().Negative()); // JD012
AnyInt32 drawn = pool.Generate(); // a recipe, not a number
Compliant
IAny<int> pool = Any.OneOf(Any.Int32().Positive().Generate(), Any.Int32().Negative().Generate());
int drawn = pool.Generate();
Note what the compliant form changes: the pool is built eagerly, one draw per element at construction, and Generate() then chooses among those fixed values. That is the documented semantics of a choice pool — if you wanted a fresh draw from a chosen generator on every call, that is a different intent and Any.OneOf is not the tool.
What it does not flag
- A pool of ordinary values, or of generated values.
- A
OneOfon any type other thanAny/AnyContext. - A pool whose generators have different types — the compiler already refuses it.