1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Reject a model field set that declares a nullable-column field `foo`
//! alongside a real field literally named `fooIsSet`.
//!
//! Same defect class as `builder_setter_collisions` (that module's doc
//! comment coins the phrase): `cratestack-client-dart/src/patch_touch.rs`
//! mechanically derives a sibling `{field}IsSet` bool for every
//! `TypeArity::Optional` (nullable-column) field that lands in a model's
//! generated `Update{Model}Input` Dart class — the tri-state "untouched vs.
//! explicitly cleared" flag cratestack#663 introduced. That derivation has
//! no collision guard of its own: a schema that also declares a real field
//! named `fooIsSet` gets two Dart members fighting over the same generated
//! identifier (a duplicate constructor parameter, a duplicate field
//! declaration, and every reference the compiler further confuses trying
//! to recover) — `dart analyze` reports it as eight separate errors
//! (`duplicate_field_formal_parameter`, `duplicate_definition`,
//! `duplicate_named_argument` x2, `argument_type_not_assignable` x2,
//! `unchecked_use_of_nullable_value`, `missing_default_value_for_parameter`)
//! with no span pointing back at the schema line at fault. This check pins
//! the parse-time rejection instead.
//!
//! Scoped to only `model.fields`: `Update{Model}Input` (`DataClassKind::
//! Patch` in `cratestack-client-dart::context::build_template_context`) is
//! the only generated Dart class this touch flag ever appears on — `type`/
//! `view`/`auth` blocks and procedure argument lists never go through
//! `DataClassKind::Patch`, so they need no call site here.
use SourceSpan;
use crate;
/// `fields` is `(field_name, field_span, is_nullable_patch_field)` triples
/// in declaration order. `is_nullable_patch_field` must mirror exactly
/// which fields `cratestack-client-dart` actually gives an `IsSet` sibling
/// to — `TypeArity::Optional`, minus the primary-key field (dropped by
/// `Update{Model}Input`'s own `!is_primary_key` filter) and minus relation
/// fields (dropped by `scalar_model_fields`, the same filter
/// `Update{Model}Input`'s field list is built from). Passing `true` for a
/// field that filter would actually exclude over-rejects a schema that
/// generates no colliding identifier at all; passing `false` for a field it
/// would include lets a real collision through unchecked.
pub