Giter VIP home page Giter VIP logo

Comments (7)

leafpetersen avatar leafpetersen commented on August 26, 2024

Different from dart-lang/sdk#28783, but basically a dup of dart-lang/sdk#25368 . Definitely something I want to fix when I get a chance. Current behavior allows really bad code, and gives an error on correct code. Sadness.

from language.

Lootwig avatar Lootwig commented on August 26, 2024

@leafpetersen dart-lang/sdk#25368 was closed with "being covered by null safety", but doesn't resolve this issue. Below code still throws a compiler error for the getter in dart 2.14.4.

import 'dart:async';

class X {
  FutureOr<int> get f => true ? Future.value(12) : 13;
}

from language.

eernstg avatar eernstg commented on August 26, 2024

I think we could consider this issue as a request for a new rule for UP, located after the FutureOr rules:

  • UP(Future<T1>, T2) = FutureOr<T3>, where T3 = UP(T1, T2).
  • UP(T1, Future<T2>) = FutureOr<T3>, where T3 = UP(T1, T2).

It is possible that we could combine these rules with the rules about UP(FutureOr..., Future...) and achieve a tighter result, but it might also work just fine to keep all of them.

We do have some prior art for treating union types in this manner:

  • UP(T1?, T2) = S? where S is UP(T1, T2).

@leafpetersen, WDYT?

from language.

eernstg avatar eernstg commented on August 26, 2024

I removed the 'closed-duplicate' label, because we do seem to have specific elements here that aren't present in dart-lang/sdk#25368.

from language.

leafpetersen avatar leafpetersen commented on August 26, 2024

Maybe. I'm a little hesitant about introducing FutureOr where there wasn't one to begin with. We'd have to evaluate carefully what side effects result.

from language.

bwilkerson avatar bwilkerson commented on August 26, 2024

@leafpetersen This looks like a language issue rather than an implementation issue. If you agree I'll move this over to the language repo.

from language.

eernstg avatar eernstg commented on August 26, 2024

Note the following perspective on this situation: As long as we do not want to introduce FutureOr in an upper bound computation when it wasn't present in the operand types, the workaround would be to adjust an operand type:

import 'dart:async';

class X {
  FutureOr<int> get f2 => true ? Future.value(12) : 13 as FutureOr<int>;
}

We're basically weighing the inconvenience of doing this in a few locations against the potential danger of having unexpected/unwanted occurrences of types of the form FutureOr<T> for conditional expressions, list/set/map literals, and other locations where upper bound computations take place.

from language.

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.