Skip to content

Converter SPI methods for required fields should return non-optional types #20

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

Merged
merged 2 commits into from
Jun 18, 2023

Conversation

sikevux
Copy link
Contributor

@sikevux sikevux commented Jun 16, 2023

Motivation

getRequiredRequestBodyAsText currently returns C? instead of C. As the value should be required an optional in the return is causing issues.

The errors are Cannot convert value of type 'C?' to specified type and Cannot infer contextual base in reference to member 'text'

Modifications

Change the return type of getRequiredRequestBodyAsText

Result

Code using a required requestBody now compiles without errors.

 ### Motivation

`getRequiredRequestBodyAsText` currently returns `C?` instead of `C`.
As the value should be required an optional in the return is causing issues.

The errors are `Cannot convert value of type 'C?' to specified type` and
`Cannot infer contextual base in reference to member 'text'`

 ### Modifications

Change the return type of `getRequiredRequestBodyAsText`

 ### Result

Code using a required requestBody now compiles without errors.
@czechboy0
Copy link
Contributor

Thanks for the fix, this was an oversight on my part.

@simonjbeaumont simonjbeaumont changed the title Fix getRequiredRequestBodyAsText getRequiredRequestBodyAsText should return non-optional type Jun 16, 2023
@simonjbeaumont
Copy link
Collaborator

@swift-server-bot test this please

@simonjbeaumont
Copy link
Collaborator

@sikevux this is great, thank you. Is it possible to add a test case for this? Specifically something that uses the code that previously world not compile?

@czechboy0
Copy link
Contributor

Agreed, we have tests already, but adding one that does something like

let foo: String = try get... should do the trick - should not compile without the fix, and should with.

@czechboy0 czechboy0 self-requested a review June 17, 2023 09:08
Copy link
Contributor

@czechboy0 czechboy0 left a comment

Choose a reason for hiding this comment

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

Marking as needs work based on the conversation above.

@czechboy0
Copy link
Contributor

Ugh, I took a quick look and we have the same issue in a few more places:

Can you please fix those too? 🙏

 ### Modifications

All `test_get*` tests for the converters now explicitly set the expected type.

Fix the original bug for the following functions as well:
* `getRequiredHeaderFieldAsText<T: _StringConvertible>`
* `getRequiredHeaderFieldAsText`

 ### Results

All tests pass without issue, after applying the fix

 ### Test plan

Made the changes to the unit tests. Observed code not compiling anymore.
Applied fixes. Tests now compile and pass.
@sikevux
Copy link
Contributor Author

sikevux commented Jun 17, 2023

Ugh, I took a quick look and we have the same issue in a few more places:

Can you please fix those too? 🙏

Yeah. Modified all the get tests to explicitly set the type just to make sure there's no more. Seems to be all of them now 😸

@sikevux sikevux requested a review from czechboy0 June 17, 2023 17:46
Copy link
Contributor

@czechboy0 czechboy0 left a comment

Choose a reason for hiding this comment

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

Great, thank you!

Copy link
Collaborator

@simonjbeaumont simonjbeaumont left a comment

Choose a reason for hiding this comment

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

Awesome. Thanks @sikevux!

@simonjbeaumont simonjbeaumont changed the title getRequiredRequestBodyAsText should return non-optional type Converter SPI methods for required fields should return non-optional types Jun 18, 2023
@simonjbeaumont simonjbeaumont merged commit e81f70f into apple:main Jun 18, 2023
@simonjbeaumont simonjbeaumont added the 🔨 semver/patch No public API change. label Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants