Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit e34247f

Browse files
authored
Support lambda inference for constructors. (#183)
1 parent 5b17b90 commit e34247f

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.0-alpha+1
2+
3+
* Also infer `Constructor.lambda` for `factory` constructors.
4+
15
## 3.0.0-alpha
26

37
* Using `equalsDart` no longer formats automatically with `dartfmt`.

lib/src/specs/constructor.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ abstract class Constructor extends Object
5454
bool get factory;
5555

5656
/// Whether this constructor is a simple lambda expression.
57+
@nullable
5758
bool get lambda;
5859

5960
/// Name of the constructor - optional.
@@ -100,7 +101,7 @@ abstract class ConstructorBuilder extends Object
100101
bool factory = false;
101102

102103
/// Whether this constructor is a simple lambda expression.
103-
bool lambda = false;
104+
bool lambda;
104105

105106
/// Name of the constructor - optional.
106107
String name;

lib/src/specs/constructor.g.dart

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: code_builder
2-
version: 3.0.0-alpha
2+
version: 3.0.0-alpha+1
33
description: A fluent API for generating Dart code
44
author: Dart Team <[email protected]>
55
homepage: https://github.com/dart-lang/code_builder

test/specs/class_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,21 @@ void main() {
264264
);
265265
});
266266

267+
test('should create a class with an implicit factory lambda constructor', () {
268+
expect(
269+
new Class((b) => b
270+
..name = 'Foo'
271+
..constructors.add(new Constructor((b) => b
272+
..factory = true
273+
..body = refer('_Foo').newInstance([]).code))),
274+
equalsDart(r'''
275+
class Foo {
276+
factory Foo() => new _Foo();
277+
}
278+
'''),
279+
);
280+
});
281+
267282
test('should create a class with a constructor with a body', () {
268283
expect(
269284
new Class((b) => b

0 commit comments

Comments
 (0)