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

Commit 165e9a7

Browse files
authored
forward Scope in returns and constructors (#44)
* forward Scope in returns and constructors * add test * changelog + version bump
1 parent 864759f commit 165e9a7

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.0-alpha+8
2+
3+
- Fix an import scoping bug in `return` statements and named constructor invocations.
4+
15
## 1.0.0-alpha+7
26

37
- Make use of new analyzer API in preparation for analyzer version 0.30.

lib/src/builders/expression/return.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class _AsReturn extends TopLevelMixin implements StatementBuilder {
1616
Statement buildStatement([Scope scope]) {
1717
return astFactory.returnStatement(
1818
$return,
19-
_value.buildExpression(),
19+
_value.buildExpression(scope),
2020
$semicolon,
2121
);
2222
}

lib/src/builders/method.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ class _NormalConstructorBuilder extends Object
492492
null,
493493
null,
494494
null,
495-
returnType.buildType().name,
495+
returnType.buildType(scope).name,
496496
_name != null ? $period : null,
497497
_name != null ? stringIdentifier(_name) : null,
498498
buildParameterList(scope),

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: 1.0.0-alpha+7
2+
version: 1.0.0-alpha+8
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/e2e_test.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ void main() {
8484
reference('_module').invoke('getDep1', []),
8585
reference('_module').invoke('getDep2', []),
8686
]),
87-
)..addAnnotation(lib$core.override)));
87+
)..addAnnotation(lib$core.override))
88+
..addMethod(new MethodBuilder(
89+
'instantiateAndReturnNamedThing',
90+
returnType: thingRef,
91+
)..addStatement(thingRef.namedNewInstance('named', []).asReturn())));
8892
expect(
8993
lib,
9094
equalsSource(
@@ -99,6 +103,10 @@ void main() {
99103
100104
@override
101105
_i2.Thing getThing() => new _i2.Thing(_module.getDep1(), _module.getDep2());
106+
107+
_i2.Thing instantiateAndReturnNamedThing() {
108+
return new _i2.Thing.named();
109+
}
102110
}
103111
''',
104112
pretty: true,

0 commit comments

Comments
 (0)