Coder Social home page Coder Social logo

Comments (2)

lrhn avatar lrhn commented on July 18, 2024

The conditional operator, ?/:, is an expression so it needs to have a static type. Its type is found as an upper bound of the static types of the two branches.

Here that's TInacccessibleMessage and TMessage.
Those two types have multiple common superinterfaes, Indexable, Versionable, Cacheable, EquatableMixin and maybeInaccessbileMessage. Each of those can be an upper bound of the two types, and the upper bound algorithm chooses Cacheable because it's "most specific" in some particular metric.
Not what you wan't, but not wrong.

Then you get an error because the context wants a MaybeInaccessibleMessage.

Luck has it that @stereotype441 has already implemented a better upper bound for cases precisely like this, where the result wouldn't match the context, but each branch's type would. It will then use the context type instead.
You'll have to wait for the next Dart release to get that behavior. Until then, either just stick with the if statements. (I personally find them more readable than the conditional expression), or add an as MaybeInaccessibleMessage cast on one of the branches (might have to silence an "unnecessary cast" warning, though).

So "fixed", just not released yet.

from sdk.

busslina avatar busslina commented on July 18, 2024

Thank you very much :) @lrhn

from sdk.

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.