Skip to content
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

[bgen] Improve nullability detection to detect the nullability attributes the C# compiler generates. Fixes #17130. #21099

Merged
merged 4 commits into from
Aug 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
NullAllowed takes precedence.
  • Loading branch information
rolfbjarne committed Aug 23, 2024
commit 651038d39f7e7e50d1daf208c69d07670623cc14
6 changes: 6 additions & 0 deletions src/bgen/AttributeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,16 @@ public bool IsNullable (ICustomAttributeProvider provider)
if (attributes is null)
return false;

// first check if any of the attributes are [NullAllowed]
foreach (var attrib in attributes) {
var attribType = attrib.GetAttributeType ();
if (attribType.Name == "NullAllowedAttribute")
return true;
}

// then check for [Nullable]
foreach (var attrib in attributes) {
var attribType = attrib.GetAttributeType ();
if (attribType.Name == "NullableAttribute") {
// https://codeblog.jonskeet.uk/2019/02/10/nullableattribute-and-c-8/
if (attrib.ConstructorArguments.Count == 1) {
Expand Down
Loading