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

Commit 8d2ee42

Browse files
authored
Fix bug and get ready to release. (#164)
1 parent 25571e3 commit 8d2ee42

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

CHANGELOG.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 2.2.0-dev
1+
## 2.2.0
22

33
* Imports are prefixed with `_i1` rather than `_1` which satisfies the lint
44
`lowercase_with_underscores`. While not a strictly breaking change you may
@@ -31,6 +31,27 @@ void main() {
3131

3232
* `literalList` accepts an `Iterable` argument.
3333

34+
* Fixed an NPE when a method had a return type of a `FunctionType`:
35+
36+
```dart
37+
void main() {
38+
test('should create a method with a function type return type', () {
39+
expect(
40+
new Method((b) => b
41+
..name = 'foo'
42+
..returns = new FunctionType((b) => b
43+
..returnType = refer('String')
44+
..requiredParameters.addAll([
45+
refer('int'),
46+
]))),
47+
equalsDart(r'''
48+
String Function(int) foo();
49+
'''),
50+
);
51+
});
52+
}
53+
```
54+
3455
## 2.1.0
3556

3657
We now require the Dart 2.0-dev branch SDK (`>= 2.0.0-dev`).

lib/src/emitter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class DartEmitter extends Object
344344
output.write('static ');
345345
}
346346
if (spec.returns != null) {
347-
spec.returns.type.accept(this, output);
347+
spec.returns.accept(this, output);
348348
output.write(' ');
349349
}
350350
if (spec.type == MethodType.getter) {

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: 2.2.0-dev
2+
version: 2.2.0
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/method_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ void main() {
9999
);
100100
});
101101

102+
test('should create a method with a function type return type', () {
103+
expect(
104+
new Method((b) => b
105+
..name = 'foo'
106+
..returns = new FunctionType((b) => b
107+
..returnType = refer('String')
108+
..requiredParameters.addAll([
109+
refer('int'),
110+
]))),
111+
equalsDart(r'''
112+
String Function(int) foo();
113+
'''),
114+
);
115+
});
116+
102117
test('should create a method with generic types', () {
103118
expect(
104119
new Method((b) => b

0 commit comments

Comments
 (0)