Giter Site home page Giter Site logo

Comments (6)

RioMcBoo avatar RioMcBoo commented on July 18, 2024

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.

gurustron avatar gurustron commented on July 18, 2024

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.

RioMcBoo avatar RioMcBoo commented on July 18, 2024

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.

RioMcBoo avatar RioMcBoo commented on July 18, 2024

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 ((
image
image
image

from roslyn.

RioMcBoo avatar RioMcBoo commented on July 18, 2024

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.

RioMcBoo avatar RioMcBoo commented on July 18, 2024

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.

image

from roslyn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.