Comments (4)
var hides the fact that the variable is nullable
This would prevent 'var' from ever being used. As far as the language is concerned, 'var' is always nullable for reference types.
We also cannot change this as that will cause build breaks for anyone upgrading.
from roslyn.
Thanks for your response. Can you clarify? I don't understand your comment "prevent 'var' from ever being used".
I'm imagining "apparent" logic that could act as such for different signatures:
Assembly GetEntryAssembly()' -- Type is apparent, use
var
Assembly? GetEntryAssembly()' -- Type is not apparent, use explicit type
Per your second point, as compatibility is a concern, I suggest a new style option that requires an explicit type used when the type is nullable in a nullable context. This could be defaulted to off to ensure compatibility.
from roslyn.
Can you clarify? I don't understand your comment "prevent 'var' from ever being used".
in all place where you use 'var' with a reference type, the type is T?
from teh perspective of the language/compiler.
You said:
In our opinion, nullable types should not be considered 'apparent' when in the nullable context.
That would mean that if you turned on csharp_style_var_when_type_is_apparent
we would not ever suggest 'var' for a reference type in nullable contexts, which would be massively bad :)
from roslyn.
Per your second point, as compatibility is a concern, I suggest a new style option that requires an explicit type used when the type is nullable in a nullable context
In hte past we've rejected this idea as every single developer has a different view on this topic. We went with the majority view when designing the option and have stuck with that to keep broad consistency across the ecosystem. We do not think knobs/options helps here.
from roslyn.
Related Issues (20)
- MSBuildWorkspace.OpenProjectAsync() does not load anything HOT 4
- New APIs to support "Ref Struct Interfaces" feature HOT 1
- Autocompletion prioritizes more distant entry
- Duplicate `.override method` generation HOT 2
- Debug Assertion error ConversionsBase.ClassifyImplicitExtensionMethodThisArgConversion
- Overload resolution ambiguity introduced by SDK 8.0.300-preview.24203.14 HOT 2
- Type arguments are not being inferred correctly from method group HOT 2
- `CS1591` fires for protected members on sealed types HOT 7
- IDE0028/IDE0300 is not reported for overloaded methods HOT 1
- EnC: display class might have no synthesized members
- Confusing nullability warning is reported for a deconstruction
- Erroneous "Use of unassigned local variable" for out parameter used inside collection expression HOT 1
- Errors for scoped differences in override indexers are missing in some cases HOT 1
- VB Span Perf Issue HOT 2
- F1 on type parameter symbols declared in source opens MSDN at completely unrelated pages
- Debug breakpoint step over throws an access violation exception
- Trying to jump out of local function after a using declaration causes internal error: 'given key was not present in dictionary' HOT 3
- Signature help does not appear for target typed new with partial parameter HOT 1
- error MSB6006: "csc.dll" exited with code 139 on almost empty project HOT 1
- Collection expression overload resolution should chose type with valid .Add method HOT 2
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 roslyn.