Comments (2)
@Evangelink, @valhristov This is one of the bigger bugs that I left behind. I started fixing it in https://github.com/tamasvajk/sonar-csharp/tree/feature/152, but I rarely find the time to work on it.
As I see, this problem is not just about Nullable<bool>
, but nullables altogether.
x = GetNullableInt();
if (x > 5)
{
}
else if (x <= 5) // seemingly always true, but if x is null, then > and <= returns false
{
}
I think one way to solve this issue is to
- introduce a
NullableSymbolicValue
, and - in operations (binary and unary symbolic values) check if any of the operands is
NullableSymbolicValue
, and if so, then the operation is a lifted op, and should behave accordingly.
Branch implements point 1. Point 2 is a bit tedious, and before I got there I realized that this solution leads a bit too far, namely (implicit) type changes and casts should be handled in some form:
Currently, for int? i = (int?)5;
the data flow engine assigns the same SV to 5
, (int?)5
and i
. But from now on we'd need not null SV_1
for 5
, and not null NullableSV_2
for the other two. There are multiple forms of this problem:
int? i = 5;
, the same as above.int? i = null;
, whereSV_null
needs to be differentiated fromNullableSV_1
with null constraint.
So this note is just to let you know that the branch is there, and could be continued, but before that some decision needs to be made. (And I guess, this should not come from a contributor.)
Also, I would be interested how the JS team handles type changes. I'm guessing (I vaguely remember) they are assigning "type" constraints to symbolic values. Maybe that's the way to go here too, but introducing a dedicated SV type for Nullable<T>
seemed more straight forward for a statically typed language.
from sonar-dotnet.
The problem is that we set a true or false constraint on SV_x when a constraint is set on x == true, however there's a third option that the x == true is false due to x being null, and == being the lifted operator.
from sonar-dotnet.
Related Issues (20)
- Fix S6967 FP: Issues should not be raised in autogenerated code HOT 1
- Fix S6967 FP: controller without model HOT 1
- Fix S6964 FN: Rule should raise in case of value type property annotated with RequiredAttribute HOT 3
- Fix S6966 FP: MongoDB Find can not be replaced by FindAsync HOT 2
- Fix S6966 FP: EntityFrameworks DbContext/DBSet Add/AddRange methods are preferred over their Asnyc counterpart HOT 4
- Fix S6964 FP: Don't raise on properties annotated with the JsonRequiredAttribute HOT 1
- S6964: Issue is reported on the attribute instead of the property
- Fix S2737 FP: Catch clause with when shouldn't warn HOT 1
- Fix S6964 FP: Should not raise for reference properties in nullable context HOT 3
- Fix S6964 FP: Do not raise in properties with required modifier HOT 3
- Metrics analyzer for Razor: Lines of code are outside the range of the file HOT 1
- TestFramework: dotnet preview versions are not supported
- TestFramework: razor analysis is not supported starting with dotnet 8.0.5
- New Rule Idea: Do not convert collections to strings when using Microsoft.Extensions.Logging HOT 4
- Fix S6966 FP: Do not use AddAsync with EF Core HOT 3
- Fix S6966 FP/FN: Should not raise for EF-Core known methods HOT 2
- Fix SA1010 FP: Use new collection initializer should not issue a warning SA1010 HOT 2
- Some codes not showing on Visual Studio HOT 1
- Update RSPEC before 9.25.1 release HOT 1
- Address S6967 FP: Raises when model is validated through helper method HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sonar-dotnet.