Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit c11cd33

Browse files
committed
feat(parser): Do not eat NoSuchMethod errors in getters
1 parent 7a3ad21 commit c11cd33

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/parser.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,18 @@ getterChild(value, childKey) {
162162
InstanceMirror instanceMirror = reflect(value);
163163
Symbol curSym = new Symbol(childKey);
164164

165+
// TODO(deboer): I don't like this try block.
166+
// It should be replaced with a if(instanceMirror.hasField(curSym)) block.
167+
// But hasField doesn't exist. Checking the variables + getters maps almost
168+
// works, but it doesn't support mixins.
165169
try {
166170
// maybe it is a member field?
167171
return [true, instanceMirror.getField(curSym).reflectee];
168172
} on NoSuchMethodError catch (e) {
173+
// TODO(deboer): I want a NoSuchInstanceGetter error instead.
174+
if (!e.toString().contains('has no instance getter')) {
175+
rethrow;
176+
}
169177
// maybe it is a member method?
170178
if (instanceMirror.type.members.containsKey(curSym)) {
171179
MethodMirror methodMirror = instanceMirror.type.members[curSym];

test/parser_spec.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,13 @@ main() {
426426
Parser.parse('foo()')(new ScopeWithErrors());
427427
}).toThrow('foo to you');
428428
});
429+
430+
431+
it('should throw on NoSuchMethod exceptions in getters', () {
432+
expect(() {
433+
Parser.parse('nsm')(new NSMGetter());
434+
}).toThrow('method not found: \'notAMethod\'');
435+
});
429436
});
430437

431438
describe('setters', () {
@@ -908,3 +915,8 @@ class ScopeWithErrors {
908915
String get boo => throw "boo to you";
909916
String foo() => throw "foo to you";
910917
}
918+
919+
class NSMGetter {
920+
var obj;
921+
String get nsm => obj.notAMethod;
922+
}

0 commit comments

Comments
 (0)