Follow-up to SpineEventEngine/validation#146.
The Spine Validation Compiler now rejects, at compile time, explicit (required) applied to a field of type google.protobuf.Empty — including repeated google.protobuf.Empty and map<_, google.protobuf.Empty>. Such a field cannot be satisfied at runtime because every Empty instance equals the default instance, so the generated check is unsatisfiable.
CoreJvm Compiler enforces an implicit (required) rule for ID fields in command messages and entity states. The same compile-time error should be produced when those implicitly-required ID fields are of type google.protobuf.Empty. Without this follow-up, implicitly-required Empty ID fields produce the same runtime "always invalid" outcome the validation change just eliminated for the explicit case.
Affected reactions
Audit and update each reaction that asserts an implicitly-required first/ID field, rejecting any such field typed as google.protobuf.Empty (singular, repeated, or map<_, Empty>):
base/src/main/kotlin/io/spine/tools/core/jvm/field/RequiredIdReaction.kt
entity/src/main/kotlin/io/spine/tools/core/jvm/entity/EntityStateIdReaction.kt
signal/src/main/kotlin/io/spine/tools/core/jvm/signal/CommandTargetReaction.kt (and any sibling signal-ID reaction that enforces the implicit first-field rule)
Reference implementation
Mirror the wording and structure of the new check in the validation repo: context/src/main/kotlin/io/spine/tools/validation/option/required/RequiredOption.kt — see checkFieldIsNotEmpty(...) and the private FieldType.refersToEmpty() extension. The error message format used there:
The field <qualifiedName> of type <fieldType.name> cannot be marked as (required) because google.protobuf.Empty has no fields and its instances are always equal to the default value.
Tests
Add a compile-fail fixture per affected reaction, analogous to the new RequiredEmptyField / RequiredRepeatedEmpty / RequiredMapWithEmptyValue fixtures in context-tests/src/testFixtures/proto/spine/validation/required_option_spec.proto on the validation side.
See also
Follow-up to SpineEventEngine/validation#146.
The Spine Validation Compiler now rejects, at compile time, explicit
(required)applied to a field of typegoogle.protobuf.Empty— includingrepeated google.protobuf.Emptyandmap<_, google.protobuf.Empty>. Such a field cannot be satisfied at runtime because everyEmptyinstance equals the default instance, so the generated check is unsatisfiable.CoreJvm Compiler enforces an implicit
(required)rule for ID fields in command messages and entity states. The same compile-time error should be produced when those implicitly-required ID fields are of typegoogle.protobuf.Empty. Without this follow-up, implicitly-requiredEmptyID fields produce the same runtime "always invalid" outcome the validation change just eliminated for the explicit case.Affected reactions
Audit and update each reaction that asserts an implicitly-required first/ID field, rejecting any such field typed as
google.protobuf.Empty(singular,repeated, ormap<_, Empty>):base/src/main/kotlin/io/spine/tools/core/jvm/field/RequiredIdReaction.ktentity/src/main/kotlin/io/spine/tools/core/jvm/entity/EntityStateIdReaction.ktsignal/src/main/kotlin/io/spine/tools/core/jvm/signal/CommandTargetReaction.kt(and any sibling signal-ID reaction that enforces the implicit first-field rule)Reference implementation
Mirror the wording and structure of the new check in the
validationrepo:context/src/main/kotlin/io/spine/tools/validation/option/required/RequiredOption.kt— seecheckFieldIsNotEmpty(...)and the privateFieldType.refersToEmpty()extension. The error message format used there:Tests
Add a compile-fail fixture per affected reaction, analogous to the new
RequiredEmptyField/RequiredRepeatedEmpty/RequiredMapWithEmptyValuefixtures incontext-tests/src/testFixtures/proto/spine/validation/required_option_spec.protoon thevalidationside.See also
(required)set on anEmptyfield validation#146improve-console-output, commit `a7a1a3e033` series): addscheckFieldIsNotEmptytoRequiredReactionand migrates the runtime "always invalid" test to a compile-fail fixture set incontext-tests.