Wrongly thinks parens are unnecessary.
If I have a nullable object that has a non-nullable struct property, but I null coalesce into a nullable struct type, parens are (seemingly) necessary to get it to compile.
readonly record struct MyStruct(int Value);
sealed record class MyClass(MyStruct Property);
MyClass? maybeGetObject() => null; // make it not sure if null or not
MyClass? maybeObject = maybeGetObject();
MyStruct value = (maybeObject?.Property!).Value;
The parentheses are considered unnecessary, but if they are removed then the expression evaluates to a MyStruct?
instead of MyStruct
which is either an error if assigning to MyStruct
or else will infer type wrongly. The parens are not redundant here.
Please sign in to leave a comment.
Hello Dave Cousineau, thank you for your report. I've submitted a new issue to our bug tracker about this: Removing seemingly redundant parentheses causes "Cannot convert source type..." error. Please comment or vote for it to get notifications about status changes. Thank you!