-
Notifications
You must be signed in to change notification settings - Fork 514
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
Add C# 8 nullability annotations to bindings #6154
Comments
Question: is adding/removing the nullability annotation from an existing binding a breaking change? |
@rolfbjarne I don't think it is (but need to confirm [1]) [1] guessing it's a custom attribute |
Hello, I know you guys are busy with Xcode 11 and iOS 13 stuff but I was wondering if you have a timeline in mind for this feature, giving that .NET Core 3.0 (and C# 8) release date is getting closer - https://www.dotnetconf.net/ Thank you, |
@cosminstirbu we don't have a timeline yet, but I think it's safe to say it won't happen before our Xcode 11 / iOS 13 support is out. After that we'll probably have a look at what we'll do and how to prioritize it. |
I want to leave this doc link for brevity, as it can enhance nullability annotation information: |
Now that Xcode 11 / iOS 13 support is fairly stable, are there plans to move this forward? |
There's a work-in-progress PR |
PR #7570 has landed in master and being backported to d16-7 |
PR #8335 adds and enable xtro rule |
xtro rule and some (partial) updates to bindings are merged with #8335 |
I've recently cloned https://github.com/xamarin/net5-samples and noticed that it references a Xamarin.iOS version that already includes some NRT work. However I find it a bit confusing that I receive a warning ( On the Swift side, the property is defined as Also, I couldn't tell from the C# docs what is the C# 8 equivalent of Swift's
This is the sample
If this is something that you were planning to address then please excuse my eagerness on poking around with this feature 😄 |
@cosminstirbu short answer: yes, that's the step "Fix the bindings" in the issue's description. Long answer Xamarin.iOS/Mac added nullability many years before Apple did. At the time there was very little and often incorrect documentation (web or headers) if Eventually Apple added their own annotations (and they was quite a bit of errors and changes since then). Xamarin.iOS/Mac started to use them for new bindings but we kept our own for the older ones. In PR #8335 you can see three things:
I can't say when this will (backlog) be completed... However it's something that is quite easy to contribute. It's largely (90%) editing the bindings and updating (deleting) the |
Thanks for providing more context. I'd like to take a stab at it (ideally maybe on a smaller framework just to get familiar with the process) if you could point me to a guide / documentation on how we could contribute to add missing nullability annotations. |
Look at the There's a Smaller ones means less works :) E.g. you might want to start with
Once complete (and when xtro does not report errors) then you can submit a PR for review. note: the above steps assume you have cloned xamarin-macios and built it ping us on gitter #macios-community if you have issues with the steps above |
I use Rider for my Xamarin.iOS IDE and I've started to notice warnings related to nullability that seem to be incorrect. For example: public class MessageViewController : UIViewController
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
if (View.Window != null) // warning: Expression is always true
{
...
}
if (PresentedViewController == null) // warning: Expression is always false
{
... // warning with dimmed code: Code is heuristically unreachable
}
}
} In that snippet, it's perfectly valid for I assume these are ReSharper (opposed to Roslyn) warnings, but do you happen to know if these warnings are being driven by incorrect annotations in Xamarin.iOS? If so, is there an easy way for me to fix these as I find them? Would it be okay for me to just open PRs as I run into individual properties that are wrong, or would you prefer an entire framework to be corrected in a single PR? |
I just looked at the ignore file for UIKit, and although it's a few hundred lines of In my previous message I asked if it would be okay to update properties individually as I run into them, but it seems like it would probably be best to just fix all of the attributes in one pass. I'd be willing to do that assuming nobody else has started yet. (And perhaps after fixing a smaller framework first, such as Photos.) If that's something you're okay with me doing, is there a particular branch I should branch off of? Or would it be best to wait until the Xcode 12 SDK changes get merged back into main? |
We'll be happy for any contribution, so either way works, but doing them all in one pass is probably going to be less work for all of us if you plan on doing them all anyway.
Of course!
There's nobody working on this that we know of, so you can pick any framework you want.
The
Yes, this would be best to avoid merge conflicts, but it shouldn't be long until it's done (a few days at most, this is the PR where we merge the Xcode 12 changes in to main: #9692) |
I'm moving this to the .NET 7 milestone, we've done a lot of the annotations, but it's still a work in progress, and there will be some left over for .NET 7. |
These changes correct some of the nullability attributes for the UIKit bindings. Although UIKit has several hundred lines of xtro-sharpie ignores related to nullability, this PR only fixes a few of them. I wasn't sure where to draw the line, but in the end, I essentially fixed most of `UIViewController` and all of `UITableView` and `UICollectionView`. These classes were the ones that led to the most `// ReSharper disable` comments being added in my team's codebase, and/or that led to crashes being introduced by devs following ReSharper's suggestions to remove "unnecessary" null-checks. These changes were largely based on the instructions given by @spouliot in [#6154](#6154 (comment)). However, I noticed the xtro-sharpie ignore files have been duplicated in the `api-annotations-dotnet` directory since then, so I updated the .ignore and .todo files in that directory as well. If the process has changed since that comment was written, I can make any additional changes that are needed. Co-authored-by: Rolf Bjarne Kvinge <[email protected]> Co-authored-by: Manuel de la Pena <[email protected]>
There has been a lot of work done here already, but we're not done yet, so I'm moving this to .NET 8. |
Xamarin.iOS|Mac bindings already support
[NullAllowed]
. This controls ifnull
checks are generated inside (the body of) API bindings.We often talked about doing more tooling but it did not yet materialize. Now the upcoming C# 8 supports nullability annotations so our attributes are even more useful - with even less work on our side (tooling wise).
Steps
[x]
Add nullability support to xtrospection tests - so we know where our bindings are missing (or extra)[NullAllowed]
. The results can be ignore until we're ready for the next step;[ ] Fix bindings (taking care not to create a merge hell with other existing/upcoming work). This will also eliminate recurrent bugs when we're missing
[NullAllowed]
(since usingnull
is not possible).[x]
Add C#8 nullability annotations to the generatorExample
This binding
currently generate
but would now generate
note the extra
?
on the parameter typesThe text was updated successfully, but these errors were encountered: