Don't attempt to record reference to a named parameter of a synthetic function.

R=brianwilkerson@google.com, paulberry@google.com
BUG=

Review URL: https://codereview.chromium.org/2537883002 .
This commit is contained in:
Konstantin Shcheglov 2016-11-29 11:41:55 -08:00
parent 636e7b559b
commit 86866a3116
2 changed files with 19 additions and 0 deletions

View file

@ -440,6 +440,13 @@ class _IndexContributor extends GeneralizingAstVisitor {
false) {
return;
}
// Ignore named parameters of synthetic functions, e.g. created for LUB.
// These functions are not bound to a source, we cannot index them.
if (elementKind == ElementKind.PARAMETER &&
element is ParameterElement &&
element.enclosingElement.isSynthetic) {
return;
}
// Add the relation.
assembler.addElementRelation(element, kind, offset, length, isQualified);
}

View file

@ -814,6 +814,18 @@ main() {
assertThat(element)..isReferencedAt('p: 1', true);
}
test_isReferencedBy_synthetic_leastUpperBound() async {
await _indexTestUnit('''
int f1({int p}) => 1;
int f2({int p}) => 2;
main(bool b) {
var f = b ? f1 : f2;
f(p: 0);
}''');
// We should not crash because of reference to "p" - a named parameter
// of a synthetic LUB FunctionElement created for "f".
}
test_isReferencedBy_TopLevelVariableElement() async {
provider.newFile(
_p('$testProject/lib.dart'),