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

Clarify type validation error message for == expression #6387

Open
anandthakker opened this issue Mar 23, 2018 · 1 comment
Open

Clarify type validation error message for == expression #6387

anandthakker opened this issue Mar 23, 2018 · 1 comment

Comments

@anandthakker
Copy link
Contributor

@ChrisLoer points out that the documentation for "==" could be a bit confusing. The docs say:

Equality is strictly typed: values of different types are always considered not equal

That is true for, e.g., ["==", ["get", "x"], 10] applied to {properties: {x: "10"}}. However, it's not true for an expression like ["==", "10", 10], which actually fails to typecheck with the message Cannot compare string and number. This error message appears to be in contradiction with the docs.

Let's clarify the message to something like:

Cannot compare ${toString(lhs.type)} and ${toString(rhs.type)}: since these types are different, "==" would always return false. Consider using "to-${toString(lhs.type)}" or "to-${toString(rhs.type)}" in order to compare two values of the same type.

@anandthakker
Copy link
Contributor Author

Another option here is to simply collapse ["==", "10", 10] to false (instead of failing validation), maybe emitting a warning in case it's due to typo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants