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

Commit bde52ab

Browse files
committed
fix(parser): Correctly distinguish NoSuchMethodError
When evaluating 'a.foo' we could get NoSuchMethodError due to 'a' not having 'foo' or 'a' has 'foo' and the getter throws NoSuchMethodError. Fix #504
1 parent 217839e commit bde52ab

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

bin/parser_generator_for_spec.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ main(arguments) {
9090
'a().name',
9191
'a[x()]()',
9292
'boo',
93+
'getNoSuchMethod',
9394
'[].count(',
9495
'false',
9596
'false && run()',

lib/core/parser/eval_access.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,14 @@ abstract class AccessReflective {
8989
_cachedValue = mirror;
9090
return result;
9191
} on NoSuchMethodError catch (e) {
92-
var result = createInvokeClosure(mirror, symbol);
93-
if (result == null) rethrow;
94-
_cachedKind = CACHED_VALUE;
95-
return _cachedValue = result;
92+
if (isNoSuchMethodDueToGetField(e)) {
93+
var result = createInvokeClosure(mirror, symbol);
94+
if (result == null) rethrow;
95+
_cachedKind = CACHED_VALUE;
96+
return _cachedValue = result;
97+
} else {
98+
rethrow;
99+
}
96100
} on UnsupportedError catch (e) {
97101
var result = createInvokeClosure(mirror, symbol);
98102
if (result == null) rethrow;
@@ -101,6 +105,12 @@ abstract class AccessReflective {
101105
}
102106
}
103107

108+
bool isNoSuchMethodDueToGetField(NoSuchMethodError e) {
109+
var msg = e.toString();
110+
return msg.indexOf("has no instance getter '$name'.") != -1 || // Dart VM
111+
msg.indexOf('Cannot call "$name\$') != -1; // Dart2JS
112+
}
113+
104114
_assign(scope, holder, value) {
105115
if (holder is Map) {
106116
holder[name] = value;

test/core/parser/parser_spec.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,13 @@ main() {
286286
});
287287

288288

289+
it('should pass noSuchMethExceptions through getters', () {
290+
expect(() {
291+
parser('getNoSuchMethod').eval(new ScopeWithErrors());
292+
}).toThrow("iDontExist");
293+
});
294+
295+
289296
it('should pass exceptions through methods', () {
290297
expect(() {
291298
parser('foo()').eval(new ScopeWithErrors());
@@ -936,6 +943,7 @@ class BracketButNotMap {
936943
class ScopeWithErrors {
937944
String get boo { throw "boo to you"; }
938945
String foo() { throw "foo to you"; }
946+
get getNoSuchMethod => null.iDontExist();
939947
}
940948

941949
@NgFilter(name:'increment')

0 commit comments

Comments
 (0)