Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of nullable:: does not work correctly #169

Open
popematt opened this issue Jun 11, 2021 · 1 comment
Open

Implementation of nullable:: does not work correctly #169

popematt opened this issue Jun 11, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@popematt
Copy link
Contributor

The Ion Schema Grammar allows for nullable:: to be applied to any type reference.

<TYPE_REFERENCE> ::=           <TYPE_NAME>
                   | nullable::<TYPE_NAME>
                   |           <TYPE_ALIAS>
                   | nullable::<TYPE_ALIAS>
                   |           <TYPE_DEFINITION>
                   | nullable::<TYPE_DEFINITION>
                   |           <IMPORT_TYPE>
                   | nullable::<IMPORT_TYPE>

And the example in the Core Types section of the spec says:

The core types do not include any of Ion's null.* values, but each of the types may have a weakly- or strongly-typed null value if the type name is annotated with nullable. When a strongly-typed null value is encountered, its type must agree with one of the core types of the expected type. For example, if a any_of: nullable::[int, string, struct] is expected, 5, "hi", {}, null, null.null, null.int, null.string, and null.struct are all valid values, but null.decimal is not.

Even ignoring the fact that the example does not match the grammar (nullable:: should be on a type reference, not a list of type references), the ion-schema-kotlin implementation does not do what this says. I also tried several other type definitions that are similar to the example, and the Ion Schema System consistently failed to allow the null values or ran into a StackOverflowError, unless I specifically used an ion type instead of a core type.

Given the test cases mentioned in the quoted paragraph, here are the results for the type in the example, and several similar types.

valid::[ 5, "hi", {}, null, null.null, null.int, null.string, null.struct ]
invalid::[ null.decimal ]
Type Result
type::{any_of:nullable::[int, string, struct]} test fails for null, null.null, null.struct, null.int, null.string
type::{type:nullable::{any_of:[int, string, struct]}} stack overflow error for null.decimal, null.struct, null.int, null.string
type::{any_of:[nullable::int, nullable::string, nullable::struct]} test fails for null, null.null, null.struct, null.int, null.string
type::{type:nullable::any, any_of:[nullable::int, nullable::string, nullable::struct]} stack overflow error for null.decimal, null.struct, null.int, null.string
type::{type:nullable::any} stack overflow error for null.decimal, null.struct, null.int, null.string
type::{type:$any, any_of:[nullable::int, nullable::string, nullable::struct]} All test cases pass
@popematt
Copy link
Contributor Author

Also created amazon-ion/ion-schema#38 to address the ambiguity in the spec around nullable::.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant