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

Fix nullable return types for CallMap functions #8228

Merged
merged 1 commit into from Jul 14, 2022

Conversation

othercorey
Copy link
Contributor

This adds an assertion on matching nullability since this doesn't fail isContainedBy().

Because there are a lot of types that should be nullable, this only checks return types and fixes the return types for functions that are already "passing". When the parameters for already "passing" functions are fixed, the nullable check can be run unconditionally.

If we ever want to completely ignore a null return type in the future without ignoring the entire return type, the ignore logic could be more sophisticated.

This type of special check can be done for false, but needed to limited the scope so can actually fix the signatures.

@@ -1744,7 +1744,7 @@
'datefmt_format' => ['string|false', 'formatter'=>'IntlDateFormatter', 'datetime'=>'DateTime|IntlCalendar|array|int'],
'datefmt_format_object' => ['string|false', 'datetime'=>'object', 'format='=>'mixed', 'locale='=>'string'],
'datefmt_get_calendar' => ['int', 'formatter'=>'IntlDateFormatter'],
'datefmt_get_calendar_object' => ['IntlCalendar', 'formatter'=>'IntlDateFormatter'],
'datefmt_get_calendar_object' => ['IntlCalendar|false|null', 'formatter'=>'IntlDateFormatter'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This also adds missing false.

@orklah orklah added the release:fix The PR will be included in 'Fixes' section of the release notes label Jul 8, 2022
'locale_get_region' => ['?string', 'locale'=>'string'],
'locale_get_script' => ['?string', 'locale'=>'string'],
'locale_lookup' => ['?string', 'languageTag'=>'array', 'locale'=>'string', 'canonicalize='=>'bool', 'defaultLocale='=>'string'],
'locale_parse' => ['?array', 'locale'=>'string'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These locale functions return null when locale string is too big. Do we want to ignore this possibility?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, it's a valid concern for some usage so we should allow users to guard against it. Note that Psalm has two configs (ignoreInternalFunctionNullReturn and ignoreInternalFunctionFalseReturn) that will make Psalm less strict about unhandled false/null returns from internal functions. Adding false or null to signature should not disturb users very much

@othercorey
Copy link
Contributor Author

@orklah Would you like me to add something to finish this? I'll probably have to fix the nullable parameters in parts since it would be a large number.

@AndrolGenhald
Copy link
Collaborator

Could you fix the failing test? Looks like it's a Windows only function.

@othercorey
Copy link
Contributor Author

Could you fix the failing test? Looks like it's a Windows only function.

Fixed. I thought that was a timeout that kept happening.

Had to adjust a stub for sapi_windows_cp_conv.

@orklah orklah merged commit 4fbbf82 into vimeo:4.x Jul 14, 2022
@orklah
Copy link
Collaborator

orklah commented Jul 14, 2022

Thanks!

@othercorey othercorey deleted the callmap-nullable branch July 14, 2022 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:fix The PR will be included in 'Fixes' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants