Comments (8)
This are more fitting for the Dart Language issue tracker. Also, your last suggestion are very similar to: dart-lang/language#3001
from sdk.
This are more fitting for the Dart Language issue tracker. Also, your last suggestion are very similar to: dart-lang/language#3001
Wasn't sure if that is a language feature or a compiler issue.
As you can see compiler allows to specify field names, but it does not allow to dereference them.
Please move/triage as you see fit.
from sdk.
final (int r, int g, int b) color = (1, 2, 3);
Since you have put the variable name color
in here, it means you are creating a variable named color
that contains a Record defined as the type (int r, int g, int b)
. The name of each variable in the record are not getting used so it kinda pointless besides for documentation.
Are you asking for this syntax instead should define the variable r
, g
, b
and color
? If so, it gets a bit confusing when having records with named arguments since should they also be defined as variables in your code or not?
final (int r, int g, int b) = (1, 2, 3);
Here, we don't have color
so we can assume you want to destruct the record into three variables.
from sdk.
Here, we don't have
color
so we can assume you want to destruct the record into three variables.
I know. The catch is that compiler allows these param names when record name is declared after its type declaration. And that declaration looks similar to what you get when declaring record type in parameters of other methods.
In my other example, the type of en
parameter ((int index, String s) en) => ...
is accepted by the Dart compiler, but the compilation errors come from dereferencing index
and s
there.
from sdk.
The syntaxes for types and for patterns are eerily similar, for very good reasons, which is actually why what you're trying doesn't work
The parser needs to figure out whether it is a seeing a type or a pattern, and it uses the following identifier to decide that what came before is a type, not a pattern.
So you would have to write
final (int r, int g, int b) & color = ...;
to bind all the names ... if declaration patterns allowed &
patterns. (They probably should, but today they don't.)
from sdk.
We can actually use a variant, as long as we stick to an <outerPattern>
as the outermost construct:
void main() {
final ((int r, int g, int b) && color) = (2, 3, 4);
...
}
from sdk.
The parser needs to figure out whether it is a seeing a type or a pattern, and it uses the following identifier to decide that what came before is a type, not a pattern.
I wonder if parser could delay its decision about exact type or infer a pattern for the time being until it is time to disambiguate exact type?
I used variable declaration for record, just to illustrate that compiler takes it as a valid syntax. Don't really have use for that variable (unless Dart would allow to do something like color.r
instead of direct reference to r
).
Other syntax variants discussed here and in dart-lang/language#3001 are adding some syntactic noise. Out of all, this one (:int r, :int g, :int b)
would be concise in context of list.indexed.map(((:int index, :String s)) => '$index:$s')
.
from sdk.
See also dart-lang/language#3487.
from sdk.
Related Issues (20)
- [dartfuzz] runtime/vm/code_patcher_x64.cc: 80: error: Expected `call [CODE_REG + offs]`
- [dartfuzz] runtime/vm/instructions_riscv.cc: 215: error: unreachable code
- [dartfuzz] runtime/vm/object.h: 4278: error: expected: ptr() != null()
- [dartfuzz] runtime/vm/object.cc: 17505: error: expected: !is_megamorphic || result.NumberOfChecks() >= FLAG_max_polymorphic_checks
- "Cannot invoke a native callback outside of an isolate" Flutter FFI HOT 4
- Failures on [ package:vm_service ] Automatically invoke VmService.dispose() when the service connection closes...[dart2wasm] Move type parameter bounds checks & parameter type check logic together with logic setting up variables HOT 1
- Hide `@nonVirtual` methods in autocomplete? HOT 2
- Connect to the Dart Tooling Daemon from the Analysis Server
- Dart code does not always appear in traces in devtools HOT 6
- [analyzer] Crash type 'AugmentedExpressionImpl' is not a subtype of type 'SimpleIdentifierImpl' in type cast
- [analyzer] Unsupported operation: Unhandled AugmentedExpressionImpl in identifier.
- [analyzer] No error if a local variable named `augmented` is declared inside of augmenting function
- [analyzer] No error to tear-off `augmented` inside of augmenting function
- `ConstructorDefinitionBuilder.augment` cannot augment factory constructor
- [vm] Dart AOT runtime should refuse to run snapshots with incompatible sanitizers HOT 2
- [vm] gen_snapshot without santizers should be able to create AOT snapshots to be used with AOT runtimes with sanitizers HOT 1
- [CRASH] `dart run` fails logging `Compilation did not produce any result...` and crashes with `PathNotFoundException` HOT 5
- [analyzer] add warning when abstract interface class has unused implementation.
- [analyzer] incorrectly marking as dead code when accessing record property in ternary HOT 3
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 sdk.