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
Conversation
33f4d19
to
7bf0086
Compare
@@ -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'], |
There was a problem hiding this comment.
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
.
'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'], |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
@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. |
Could you fix the failing test? Looks like it's a Windows only function. |
7bf0086
to
f28ac73
Compare
Fixed. I thought that was a timeout that kept happening. Had to adjust a stub for sapi_windows_cp_conv. |
Thanks! |
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.