Comments (7)
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.
@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.
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>
, whereT3
= UP(T1
,T2
). - UP(
T1
,Future<T2>
) =FutureOr<T3>
, whereT3
= 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?
whereS
is UP(T1
,T2
).
@leafpetersen, WDYT?
from language.
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.
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.
@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.
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)
- Consider creating `macros` repo; how to use it for `dart_model` HOT 7
- Allow a library prefix (not an import prefix) to support access to shadowed names HOT 6
- More flexibility for the `base` keyword HOT 3
- Next steps for `dart_model` prototype integration HOT 16
- Static type metadata guided shorthands and features HOT 4
- No macro.TypeDeclarationImpl for `dynamic` HOT 5
- Adoption of functional programming in the Dart language HOT 2
- Enhancing `library` and `part of` Declarations in Dart HOT 1
- Create the type `Monad` HOT 4
- Allow `import` and `part` to have wildcard path to import every lib in specific directory HOT 1
- Adding conditional imports/parts with macros. HOT 2
- Consider changing the context for the operand of `throw` to `Object`. HOT 4
- Allow statically known class fields to be used in switch statements HOT 4
- could support static extension? HOT 2
- Macro - Augment class with generic HOT 7
- Macro annotation information in yaml files next steps HOT 3
- Network paths don't work anymore with version 3.4.0 HOT 2
- "Merge to source" for macros that only need Phase 3 HOT 26
- Follow up on "spawn isolate from kernel blob" implementation
- Allow pattern `case` conditions in `while` statements. 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 language.