Skip to content

Commit

Permalink
Version 3.5.0-151.0.dev
Browse files Browse the repository at this point in the history
Merge 03a0467 into dev
  • Loading branch information
Dart CI committed May 13, 2024
2 parents 8f6000a + 03a0467 commit 7c7767e
Show file tree
Hide file tree
Showing 22 changed files with 278 additions and 171 deletions.
10 changes: 9 additions & 1 deletion pkg/analyzer/doc/process/new_language_feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ Separate issues should be created for each of the items in the list.
The following is a list of the individual features that need to be considered.
The features are listed roughly in dependency order.

- [ ] AST enhancements
- [ ] AST enhancements (`AstBuilder`)
- [ ] Resolution of directives
- [ ] Element model
- [ ] Type system updates
- [ ] Summary support
- [ ] Resolution
- [ ] `ResolutionVisitor` (resolve types)
- [ ] `ScopeResolverVisitor` (resolve simple identifiers by scope)
- [ ] `ResolverVisitor` (type-based resolution)
- [ ] Constant evaluation
- [ ] Index and search
- [ ] Warnings (annotation-based, unused\*, strict-mode-based, a few others)
- [ ] `InheritanceOverrideVerifier` (report errors and warnings related to overrides)
- [ ] `ErrorVerifier` (report other errors and warnings)
- [ ] `FfiVerifier` (report errors and warnings related to FFI)
- [ ] Unused elements warnings
- [ ] ExitDetector
- [ ] NodeLintRegistry
6 changes: 4 additions & 2 deletions pkg/analyzer/lib/src/generated/error_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -652,13 +652,15 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
try {
var element = node.declaredElement as EnumElementImpl;

var augmented = element.augmented;
_checkAugmentations(
augmentKeyword: node.augmentKeyword,
element: element,
);

_enclosingClass = element;
var augmented = element.augmented;
var declarationElement = augmented.declaration;
_enclosingClass = declarationElement;

_duplicateDefinitionVerifier.checkEnum(node);

_checkForBuiltInIdentifierAsName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,20 @@ enum E with M {
}
''');
}

test_enum_noSuperclassConstraint_augmented() async {
newFile(testFile.path, r'''
import augment 'a.dart';
mixin M {}
enum E {v}
''');

var a = newFile('$testPackageLibPath/a.dart', r'''
augment library 'test.dart';
augment enum E with M {}
''');

await resolveFile2(a);
assertNoErrorsInResult();
}
}
5 changes: 4 additions & 1 deletion pkg/dds/test/dap/integration/debug_exceptions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ main() {

// Expect that there is metadata attached that matches the file/location we
// expect.
expect(mainStackFrameEvent.source?.path, testFile.path);
expect(
mainStackFrameEvent.source?.path,
dap.client.uppercaseDriveLetter(testFile.path),
);
expect(mainStackFrameEvent.line, exceptionLine);
expect(mainStackFrameEvent.column, 5);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,6 @@ void main(List<String> args) async {
await driver.finish();
});

group('(Unsound null safety)', () {
group('(AMD module system)', () {
var setup = SetupCompilerOptions(
soundNullSafety: false,
moduleFormat: ModuleFormat.amd,
args: args,
);
runSharedTests(setup, driver);
});

group('(DDC module system)', () {
var setup = SetupCompilerOptions(
soundNullSafety: false,
moduleFormat: ModuleFormat.ddc,
args: args,
);
runSharedTests(setup, driver);
});
});

group('(Sound null safety)', () {
group('(AMD module system)', () {
var setup = SetupCompilerOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,6 @@ void main(List<String> args) async {
await driver.finish();
});

group('(Unsound null safety)', () {
group('(AMD module system)', () {
var setup = SetupCompilerOptions(
soundNullSafety: false,
moduleFormat: ModuleFormat.amd,
args: args,
);
runSharedTests(setup, driver);
});

group('(DDC module system)', () {
var setup = SetupCompilerOptions(
soundNullSafety: false,
moduleFormat: ModuleFormat.ddc,
args: args,
);
runSharedTests(setup, driver);
});
});

group('(Sound null safety)', () {
group('(AMD module system)', () {
var setup = SetupCompilerOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ main() {
''';

/// Shared tests that require a language version >=2.12.0 <2.17.0.
// TODO(nshahan) Merge with [runAgnosticSharedTests] after we no longer need to
// test support for evaluation in legacy (pre-null safety) code.
void runNullSafeSharedTests(
SetupCompilerOptions setup, ExpressionEvaluationTestDriver driver) {
group('JS interop', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ import '../shared_test_options.dart';
import 'expression_compiler_suite.dart';

void main(List<String> args) {
for (var moduleFormat in [ModuleFormat.amd, ModuleFormat.ddc]) {
group('Module format: $moduleFormat |', () {
group('Unsound null safety |', () {
runTests(SetupCompilerOptions(
soundNullSafety: false,
moduleFormat: moduleFormat,
args: args,
));
});
});
}

for (var moduleFormat in [ModuleFormat.amd, ModuleFormat.ddc]) {
group('Module format: $moduleFormat |', () {
group('Sound null safety |', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ void main(List<String> args) async {
// Set to true to enable debug output
var debug = false;

group('amd module format -', () {
for (var soundNullSafety in [true, false]) {
group('${soundNullSafety ? "sound" : "unsound"} null safety -', () {
var setup = SetupCompilerOptions(
moduleFormat: ModuleFormat.amd,
soundNullSafety: soundNullSafety,
args: args,
);
runTests(setup, verbose: debug);
});
}
group('amd module format - sound null safety -', () {
var setup = SetupCompilerOptions(
moduleFormat: ModuleFormat.amd,
soundNullSafety: true,
args: args,
);
runTests(setup, verbose: debug);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ void main(List<String> args) async {
// Set to true to enable debug output
var debug = false;

group('ddc module format -', () {
for (var soundNullSafety in [true, false]) {
group('${soundNullSafety ? "sound" : "unsound"} null safety -', () {
var setup = SetupCompilerOptions(
moduleFormat: ModuleFormat.ddc,
soundNullSafety: soundNullSafety,
args: args,
);
runTests(setup, verbose: debug);
});
}
group('ddc module format - sound null safety -', () {
var setup = SetupCompilerOptions(
moduleFormat: ModuleFormat.ddc,
soundNullSafety: true,
args: args,
);
runTests(setup, verbose: debug);
});
}
4 changes: 2 additions & 2 deletions pkg/json/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# 0.1.0-wip
# 0.20.0

- Initial release, adds the JsonCodable macro.
- Initial preview of JSON encoding and decoding with a JsonCodable macro.
28 changes: 17 additions & 11 deletions pkg/json/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
This package provides an experimental macro that encodes and decodes
user-defined Dart classes to JSON maps (maps of type `Map<String, Object?>`).
This package supports easy encoding and decoding of JSON maps (maps of type
`Map<String, Object?>`). It relies on a macro, that when applied to a
user-defined Dart class, auto-generates a `fromJson` decoding constructor
and a `toJson` encoding method.

This relies on the experimental macros language feature, and as such may be
unstable or have breaking changes if the feature changes.
Both the package itself, and the underlying macros language feature, are
considered experimental. Thus they have incomplete functionality, may be
unstable, have breaking changes as the feature evolves, and are not suitable for
production code.

## Applying the JsonCodable macro

Expand Down Expand Up @@ -30,9 +34,10 @@ class User {
}
```

Each non-nullable field in the annotated class must have an entry with the same name in the `json` map, but
nullable fields are allowed to have no key at all. The `toJson` will omit null
fields entirely from the map, and will not contain explicit null entries.
Each non-nullable field in the annotated class must have an entry with the same
name in the `json` map, but nullable fields are allowed to have no key at all.
The `toJson` will omit null fields entirely from the map, and will not contain
explicit null entries.

### Extending other classes

Expand Down Expand Up @@ -65,7 +70,8 @@ future.

## Configuration

Macro configuration is a feature we intend to add, but it is not available at this time.
Macro configuration is a feature we intend to add, but it is not available at
this time.

Because of this, field names must exactly match the keys in the maps, and
default values are not supported.
Expand All @@ -88,6 +94,6 @@ analyzer:
Note that `dart run` is a little bit special, in that the option must come
_immediately_ following `dart` and before `run` - this is because it is an
option to the Dart VM, and not the Dart script itself. For example,
`dart --enable-experiment=macros run bin/my_script.dart`. This is also how the
`test` package expects to be invoked, so `dart --enable-experiment=macros test`.
option to the Dart VM, and not the Dart script itself. For example, `dart
--enable-experiment=macros run bin/my_script.dart`. This is also how the `test`
package expects to be invoked, so `dart --enable-experiment=macros test`.
19 changes: 19 additions & 0 deletions pkg/json/example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:json/json.dart';

@JsonCodable()
class Point {
int x = 0, y = 0;
}

@JsonCodable()
class ColoredPoint extends Point {
String color = '';
}

main() {
final json = {'x': 12, 'y': 42, 'color': '#2acaea'};
var p = ColoredPoint.fromJson(json);

p.x = 100;
print('JSON ${p.toJson()}'); // Prints: JSON {x: 100, y: 42, color: #2acaea}
}
15 changes: 9 additions & 6 deletions pkg/json/lib/json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import 'dart:async';

import 'package:macros/macros.dart';

/// A macro which adds a `fromJson(Map<String, Object?> json)` constructor and
/// a `Map<String, Object?> toJson()` method to a class.
/// A macro which adds a `fromJson(Map<String, Object?> json)` JSON decoding
/// constructor, and a `Map<String, Object?> toJson()` JSON encoding method to a
/// class.
///
/// To use this macro, annotate your class with `@JsonCodable()` and enable the
/// macros experiment (see README.md for full instructions).
Expand All @@ -19,7 +20,8 @@ import 'package:macros/macros.dart';
/// the maps that they are being decoded from.
///
/// If extending any class other than [Object], then the super class is expected
/// to also have a corresponding `toJson` method and `fromJson` constructor.
/// to also have a corresponding `toJson` method and `fromJson` constructor
/// (possibly via those classes also using the macro).
///
/// Annotated classes are not allowed to have a manually defined `toJson` method
/// or `fromJson` constructor.
Expand Down Expand Up @@ -59,7 +61,8 @@ macro class JsonCodable
}
}

/// A macro which adds a `Map<String, Object?> toJson()` method to a class.
/// A macro which adds a `Map<String, Object?> toJson()` JSON encoding method to
/// a class.
///
/// To use this macro, annotate your class with `@JsonEncodable()` and enable
/// the macros experiment (see README.md for full instructions).
Expand Down Expand Up @@ -97,8 +100,8 @@ macro class JsonEncodable
}
}

/// A macro which adds a `fromJson(Map<String, Object?> json)` constructor to a
/// class.
/// A macro which adds a `fromJson(Map<String, Object?> json)` JSON decoding
/// constructor to a class.
///
/// To use this macro, annotate your class with `@JsonDecodable()` and enable
/// the macros experiment (see README.md for full instructions).
Expand Down
10 changes: 6 additions & 4 deletions pkg/json/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: json
description: >
A package which provides an experimental macro that encodes and decodes
user-defined Dart classes to JSON maps (maps of type `Map<String, Object?>`).
Easy encoding and decoding of JSON maps (maps of type `Map<String, Object?>`).
Uses a macro that auto-generates a `fromJson` decoding constructor and a
`toJson` encoding method.
repository: https://github.com/dart-lang/sdk/tree/main/pkg/json
version: 0.1.0-wip
version: 0.20.0
environment:
sdk: ^3.4.0-0
sdk: ^3.5.0-0
dependencies:
macros: ^0.1.0-0
dev_dependencies:
Expand Down
23 changes: 14 additions & 9 deletions pkg/linter/lib/src/rules/unnecessary_lambdas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,16 @@ class _Visitor extends SimpleAstVisitor<void> {

var parameters = nodeToLintParams.map((e) => e.declaredElement).toSet();
if (node is FunctionExpressionInvocation) {
if (node.function.mightBeDeferred) return;

// TODO(pq): consider checking for assignability
// see: https://github.com/dart-lang/linter/issues/1561
var checker = _FinalExpressionChecker(parameters);
if (checker.isFinalNode(node.function)) {
rule.reportLint(nodeToLint);
}
} else if (node is MethodInvocation) {
var target = node.target;
if (target is SimpleIdentifier) {
var element = target.staticElement;
if (element is PrefixElement) {
if (element.imports.any((e) => e.isDeferred)) return;
}
}
if (node.target.mightBeDeferred) return;

var tearoffType = node.staticInvokeType;
if (tearoffType == null) return;
Expand All @@ -239,8 +235,17 @@ class _Visitor extends SimpleAstVisitor<void> {
}
}

extension on LibraryImportElement {
bool get isDeferred => prefix is DeferredImportElementPrefix;
extension on Expression? {
bool get mightBeDeferred {
var self = this;
var element = switch (self) {
PrefixedIdentifier() => self.prefix.staticElement,
SimpleIdentifier() => self.staticElement,
_ => null,
};
return element is PrefixElement &&
element.imports.any((e) => e.prefix is DeferredImportElementPrefix);
}
}

extension on Element? {
Expand Down
Loading

0 comments on commit 7c7767e

Please sign in to comment.