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

Resolve NumberType | NumberArrayType ambiguity with a new SizeType #15818

Merged
merged 2 commits into from May 18, 2024

Conversation

ahocevar
Copy link
Member

@ahocevar ahocevar commented May 10, 2024

This pull request removes the only real-life need for type hints in "get" call expressions, which was needed due to an ambiguity between NumberType and NumberArrayType for -scale style properties.

With the new SizeType, it would also be possible to support styles like 'icon-size': 24 instead of 'icon-size': [24, 24], but I did not make this change here.

Copy link

📦 Preview the website for this branch here: https://deploy-preview-15818--ol-site.netlify.app/.

@ahocevar ahocevar force-pushed the size-type branch 4 times, most recently from 9a4f459 to f356c9f Compare May 10, 2024 17:02
@ahocevar ahocevar marked this pull request as ready for review May 10, 2024 17:18
'circle-scale': ['get', 'iconSize', 'number[]'],
'circle-scale': ['get', 'iconSize'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual achievement - no type hint needed any more!

@ahocevar
Copy link
Member Author

This is now ready for review.

@@ -485,6 +497,12 @@ function compile(expression, returnType, context) {
return arrayToGlsl(/** @type {Array<number>} */ (expression.value));
}

if ((expression.type & SizeType) > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since anything that includes the NumberType is already handled above, isn’t this only testing that NumberArrayType is included?

I’m only reviewing on a small device, so probably missing context, but it isn’t clear to me why we aren’t checking for more narrow types in all these ifs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I must be missing something. I see NumberArrayType is also checked right above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tschaub Looks like you're not missing anything, but that code is missing tests. Looking into it now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think SizeType should be a distinct type, like ColorType, instead of a broadened type. But I haven't been able to fully wrap my head around the types involved in the parsing and compilation phases to figure out how that works. So @tschaub, if you have an idea how that could be achieved, any help would be appreciated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I think I figured it out, @tschaub. Before I commit, I'm adding more tests.

@ahocevar ahocevar marked this pull request as draft May 12, 2024 08:24
@ahocevar ahocevar force-pushed the size-type branch 3 times, most recently from a57c160 to e10117a Compare May 12, 2024 09:00
@ahocevar ahocevar marked this pull request as ready for review May 12, 2024 09:05
@ahocevar
Copy link
Member Author

@tschaub Ready for review - tests added, SizeType is now a distinct type.

Copy link
Member

@tschaub tschaub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work on this, @ahocevar.

@ahocevar ahocevar merged commit 7ee2c92 into openlayers:main May 18, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants