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

SE - Nullable: Infer constraints for HasValue property #6850

Merged
merged 2 commits into from
Mar 3, 2023

Conversation

pavel-mikula-sonarsource
Copy link
Contributor

Part of #6812

Set BoolConstraint on .HasValue from known ObjectConstraint, if present.
Do not set NotNull for the symbol itself, as something.HasValue doesn't mean it cannot be null in this case.

@pavel-mikula-sonarsource pavel-mikula-sonarsource changed the base branch from master to feature/SE March 2, 2023 14:57
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we are on the right track.

I think a second test case would help in understanding what's going on here.

Tag("HasValueAfterNull", hasValue);
Tag("SymbolAfterNull", arg);
""";
var validator = SETestContext.CreateCS(code, ", bool? arg").Validator;

Choose a reason for hiding this comment

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

The test would be easier to read if we use int? instead. It's confusing to keep track of HasValue, arg, and BoolConstraint at the same time. Maybe add a second test case with int??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

int doesn't have any constraint on it. I wouldn't mind if you rewrite it in your PRs. As there's ToDo for you here anyway :)

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants