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

feat(parser): Do not eat NoSuchMethod errors in getters #69

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,18 @@ getterChild(value, childKey) {
InstanceMirror instanceMirror = reflect(value);
Symbol curSym = new Symbol(childKey);

// TODO(deboer): I don't like this try block.
// It should be replaced with a if(instanceMirror.hasField(curSym)) block.
// But hasField doesn't exist. Checking the variables + getters maps almost
// works, but it doesn't support mixins.
try {
// maybe it is a member field?
return [true, instanceMirror.getField(curSym).reflectee];
} on NoSuchMethodError catch (e) {
// TODO(deboer): I want a NoSuchInstanceGetter error instead.
if (!e.toString().contains('has no instance getter')) {
rethrow;
}
// maybe it is a member method?
if (instanceMirror.type.members.containsKey(curSym)) {
MethodMirror methodMirror = instanceMirror.type.members[curSym];
Expand Down
12 changes: 12 additions & 0 deletions test/parser_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ main() {
Parser.parse('foo()')(new ScopeWithErrors());
}).toThrow('foo to you');
});


it('should throw on NoSuchMethod exceptions in getters', () {
expect(() {
Parser.parse('nsm')(new NSMGetter());
}).toThrow('method not found: \'notAMethod\'');
});
});

describe('setters', () {
Expand Down Expand Up @@ -908,3 +915,8 @@ class ScopeWithErrors {
String get boo => throw "boo to you";
String foo() => throw "foo to you";
}

class NSMGetter {
var obj;
String get nsm => obj.notAMethod;
}