diff --git a/cc/google/fhir/fhir_path/fhir_path.cc b/cc/google/fhir/fhir_path/fhir_path.cc index c58dd479a..11be531a1 100644 --- a/cc/google/fhir/fhir_path/fhir_path.cc +++ b/cc/google/fhir/fhir_path/fhir_path.cc @@ -2625,6 +2625,9 @@ class ChildrenFunction : public ZeroParameterFunctionNode { for (const WorkspaceMessage& child : child_results) { const Descriptor* descriptor = child.Message()->GetDescriptor(); + if (IsPrimitive(descriptor)) { + continue; + } for (int i = 0; i < descriptor->field_count(); i++) { std::vector messages; FHIR_RETURN_IF_ERROR( diff --git a/cc/google/fhir/fhir_path/fhir_path_test.cc b/cc/google/fhir/fhir_path/fhir_path_test.cc index dcbfa2b8b..81af787fa 100644 --- a/cc/google/fhir/fhir_path/fhir_path_test.cc +++ b/cc/google/fhir/fhir_path/fhir_path_test.cc @@ -738,6 +738,8 @@ TYPED_TEST(FhirPathTest, TestFunctionChildren) { UnorderedElementsAreArray( {EqualsProto(structure_definition.snapshot().element(0)), EqualsProto(structure_definition.differential().element(0))})); + + EXPECT_THAT(TestFixture::Evaluate("(1 | 2).children()"), EvalsToEmpty()); } TYPED_TEST(FhirPathTest, TestFunctionDescendants) { @@ -763,6 +765,9 @@ TYPED_TEST(FhirPathTest, TestFunctionDescendants) { EqualsProto(structure_definition.differential().element(0)), EqualsProto( structure_definition.differential().element(0).label())})); + + EXPECT_THAT(TestFixture::Evaluate("('foo' | 'bar').descendants()"), + EvalsToEmpty()); } TYPED_TEST(FhirPathTest, TestFunctionDescendantsOnEmptyCollection) {