Comments (6)
it bugs with other types also (unsigned/unsigned and signed/signed)
[short to int]
[ushort to uint]
just look for that case (all of them):
[ushort to long]
[ushort to ulong]
[short to long]
[short to ulong]
and etc
It looks like all of these types share an implicit float conversion operator.
from roslyn.
As far as I understand this is not a bug but behavior defined in the spec (10.5.5 User-defined explicit conversions) which allows using intermediate standard explicit conversions in this case.
from roslyn.
I thought about this too. But the point is that the compiler never makes 2 implicit conversions for the same type at once. But it can convert both operands once each to a common type.
And as it turns out, all these types have a common type - float. Look, at least - why long can be converted to float?
Anyway, if it is possible (i am not sure) - it is a mistake, because you need to further convert the result of the operation to a narrower type. And here an explicit conversion is called, which means that the programmer agrees to data loss
from roslyn.
For example:
Pls make difference: with this case
I think not a single person would ever guess in his life that he could lose data here. This is not obvious at all. Moreover, this makes it difficult to create a standard wrapper type for more strictly code typing.
For example, I encountered this problem when I opened a project where all the variables were of type uint/int, and at the same time they stored seconds, milliseconds, with and without negative values, as well as Unix time. I've been back for 2 weeks now just to get everything in order, and now I got this surprise ((
from roslyn.
As far as I understand this is not a bug but behavior defined in the spec (10.5.5 User-defined explicit conversions) which allows using intermediate standard explicit conversions in this case.
Now I see your point, this is not a bug. A BUG is in opposite hand - finally it still looks weird because I cannot make an analogue of basic types in total equalence:
look at two versions of S and MS methods:
- one of them implements with basic types
- second implements with wrapped types
And it turns out that in some cases described above, this behavior changes: Just because I changed ulong to long. How to understand this logic?
I believe that either all variants of such manipulations should be prohibited, or all manipulations should be allowed.
from roslyn.
Despite this inconsistency and double standards that can confuse anyone, you can try to avoid this by using constructors instead of conversion operators. But in this case it looks too cumbersome in my opinion.
from roslyn.
Related Issues (20)
- Option to default the Extract Interface destination to "Add to current file" HOT 1
- Incorrect receiver capture with `ref C` receiver and interpolation handler
- C# needs a feature to "Show all called methods" for any given method implementation.
- Shorthand Switch Case Guards HOT 2
- Automatic line wrapping, taking into account the specified formatting and language syntax.
- Run code clean up -- Can you remove redundant blank lines like CShapier? HOT 1
- Cannot define a raw string literal ending in double-quote HOT 1
- Move more logic from the Controller.Session down to the SignatureHelpService
- Assigning members of ICollection types with collection initializers can provably cause NullReferenceExceptions HOT 4
- StaticAbstractMembersInInterfaces - Roslyn does not warn that a most-derived static interface method implementation will not be used HOT 8
- Scripting API - Operation is not supported on this platform. (when AOT published)
- A potential bug in custom string interpolation constructor resolving for `ref` parameters HOT 1
- Compile Error After Upgrading - SDK 8.0.300 - 'Class1' does not contain a definition for 'DisposeAsync' HOT 3
- Allow manually forcing a refresh of the IntelliSense database HOT 2
- Allow manually forcing a refresh of the IntelliSense database HOT 1
- "Use primary constructor" does not produce a diagnostic for an empty public parameterless constructor HOT 6
- SymbolFinder.FindReferencesAsync not returning references used as base constructor
- SymbolFinder.FindReferencesAsync not returning references used as base constructor HOT 1
- Question: MSBuildWorkspace can't open .proj file
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.