ietf-wg-jsonpath / draft-ietf-jsonpath-base

Development of a JSONPath internet draft
https://ietf-wg-jsonpath.github.io/draft-ietf-jsonpath-base/
Other
58 stars 20 forks source link

Table 13 does not show that OptionalNode is a subtype of OptionalValue #385

Closed glyn closed 1 year ago

glyn commented 1 year ago

OptionalNode is a subtype by coercion of OptionalValue, but Table 13 does not include this subtype relationship.

cabo commented 1 year ago

Not sure I like the concept of "subtype by coercion". One can be used in place of the other as it can be coerced, but that is not usually what we'd call a subtype.

glyn commented 1 year ago

That's a different point really. Table 13 already includes at least one subtype by coercion, so this issue adds another subtype by coercion.

glyn commented 1 year ago

@cabo How would you like to proceed with "subtype by coercion"? If we want to explore alternatives, I think it deserves a separate, non-editorial issue.

gregsdennis commented 1 year ago

From the spec, just below Table 14:

OptionalNode is a subtype of OptionalValue via coercion since the OptionalNode instance Node(n) can be coerced to the OptionalValue instance Value(v), where v is the value of the node n.

I disagree with the idea that coercion implies subtypes.

If I have integer and floating point numeric types, I can cast from one to the other, but that doesn't mean that either is a subtype of the other.

C# provides "implicit" casts where the compiler can infer a type cast from context. For example,

float f1 = 1.5;
int i1 = (int) f1;  // C# requires that I explicitly cast this because of data loss

int i2 = 42;
float f2 = i;  // This is an implicit cast.  int isn't a subtype, but it is compatible.

I think this is closer to what we're dealing with here. We're looking at compatibility and conversion between types, not polymorphism (as "subtype" implies).