diff --git a/lib/parser.dart b/lib/parser.dart index b355ac652..1e10b6e39 100644 --- a/lib/parser.dart +++ b/lib/parser.dart @@ -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]; diff --git a/test/parser_spec.dart b/test/parser_spec.dart index ccd8a4222..93bd7b0e2 100644 --- a/test/parser_spec.dart +++ b/test/parser_spec.dart @@ -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', () { @@ -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; +}