@@ -125,18 +125,19 @@ export class Retrieve extends Expression {
125125 if ( rhs instanceof CodeSystem ) {
126126 throw new Error ( "Operator '~' is not defined for Code ~ CodeSystem" ) ;
127127 } else if ( rhs instanceof ValueSet ) {
128- // It's not obvious that this combination should even be allowed.
129- // If in the CQL representation of the Retrieve, the terminology is a ValueSet,
130- // eg [Condition: code ~ "SomeValueSet"],
131- // the CQL-to-ELM translation may turn that into either:
132- // - a `ValueSetRef` expression (appears here as a `ValueSet`)
133- // - or an `ExpandValueSet` expression wrapping the `ValueSetRef` (appears here as a `Code[]`).
134- // Because we can't tell the original intent here, we treat the ValueSet as if it were a Code[].
128+ // It's not obvious that code ~ ValueSet and code ~ Code[] should be allowed,
129+ // when code ~ CodeSystem is disallowed. Same for operator = below.
130+ // In short, due to various translator behaviors, when `rhs` here is Code[],
131+ // it's possible it was originally written in the CQL as a Code, a List<Code>, or a ValueSet.
132+ // We can't distinguish, so we have to allow all of them.
133+ // Then, again because of translator behaviors, x ~ ValueSet could reach this point
134+ // with `rhs` either being a Code[] or a ValueSet object.
135+ // Because we can't filter it out in the Code[] path, we should allow it in the ValueSet path as well
136+ // to reduce unexpected inconsistencies.
137+ // See full description and discussion at https://github.com/cqframework/cql-execution/pull/370
135138 return rhs . hasMatch ( lhs ) ;
136139 } else if ( Array . isArray ( rhs ) ) {
137- // It's also not obvious that this should be allowed.
138- // But because the RHS is always list-promoted, there's no way to tell
139- // if the original CQL referred to a single code or to a list.
140+ // As noted above, there's no way to tell if the original CQL referred to a single code or to a list.
140141 // So, we treat the operators ~ and = to mean
141142 // "some match exists between the LHS and RHS, with the appropriate operator"
142143 // instead of the usual meaning
0 commit comments