-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
JSInterop: Enable returning null for a nullable value type #60850
base: main
Are you sure you want to change the base?
JSInterop: Enable returning null for a nullable value type #60850
Conversation
When a result value is null, and the return type is a nullable value type, Convert.ChangeType throws instead of returning the null value. dotnet#30366
Pushed a draft of what I wanted the tests to look like, gotta figure out the test fixture stuff too. |
6f7d836
to
2dad3d3
Compare
Ok I kinda figured out how the tests are supposed to work. Just have to install jdk |
2dad3d3
to
fe68842
Compare
fe68842
to
0a86864
Compare
Figured it out, tests are green now. |
Alternative: use |
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
Ready for review. |
@@ -89,7 +89,9 @@ public void SetResult(object tcs, object? result) | |||
// If necessary, attempt a cast | |||
var typedResult = result is T resultT | |||
? resultT | |||
: (T)Convert.ChangeType(result, typeof(T), CultureInfo.InvariantCulture)!; | |||
: result == null && default(T) == null // ChangeType can't convert null to value types |
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.
It seems OK to me.
@oroztocil please review
JSInterop: Enable returning null for a nullable value type
Summary of the changes (Less than 80 chars)
Description
When a result value is null, and the return type is a nullable value type, Convert.ChangeType throws instead of returning the null value, so in case off null this now uses null directly.
Fixes #30366