Fix crash while inferencing instance field type.

The type does not look correct, should it be '(dynamic) → dynamic'?
But at least it does not crash anymore.

R=paulberry@google.com
BUG=

Review URL: https://codereview.chromium.org/2511753002 .
This commit is contained in:
Konstantin Shcheglov 2016-11-17 10:23:53 -08:00
parent f82cd6bb5d
commit 225b062be8
3 changed files with 36 additions and 4 deletions

View file

@ -3143,7 +3143,7 @@ abstract class ElementImpl implements Element {
}
}
static int _findElementIndexUsingIdentical(List items, Object item) {
static int findElementIndexUsingIdentical(List items, Object item) {
int length = items.length;
for (int i = 0; i < length; i++) {
if (identical(items[i], item)) {
@ -4387,8 +4387,8 @@ class FunctionElementImpl extends ExecutableElementImpl
String identifier = super.identifier;
Element enclosing = this.enclosingElement;
if (enclosing is ExecutableElement) {
int id = ElementImpl._findElementIndexUsingIdentical(
enclosing.functions, this);
int id =
ElementImpl.findElementIndexUsingIdentical(enclosing.functions, this);
identifier += "@$id";
}
return identifier;
@ -6046,7 +6046,7 @@ class LocalVariableElementImpl extends NonParameterVariableElementImpl
String identifier = super.identifier;
Element enclosing = this.enclosingElement;
if (enclosing is ExecutableElement) {
int id = ElementImpl._findElementIndexUsingIdentical(
int id = ElementImpl.findElementIndexUsingIdentical(
enclosing.localVariables, this);
identifier += "@$id";
}

View file

@ -2961,6 +2961,9 @@ class FunctionElementForLink_Initializer extends Object
_variable.compilationUnit, this, ex))
.toList();
@override
String get identifier => '';
@override
DartType get returnType {
// If this is a variable whose type needs inferring, infer it.
@ -3084,6 +3087,18 @@ class FunctionElementForLink_Local_NonSynthetic extends ExecutableElementForLink
compilationUnit, this, ex))
.toList();
@override
String get identifier {
String identifier = _unlinkedExecutable.name;
Element enclosing = this.enclosingElement;
if (enclosing is ExecutableElement) {
int id =
ElementImpl.findElementIndexUsingIdentical(enclosing.functions, this);
identifier += "@$id";
}
return identifier;
}
@override
bool get _hasTypeBeenInferred => _inferredReturnType != null;
@ -4981,6 +4996,9 @@ abstract class VariableElementForLink
@override
bool get hasImplicitType => unlinkedVariable.type == null;
@override
String get identifier => unlinkedVariable.name;
/**
* Return the inferred type of the variable element. Should only be called if
* no type was explicitly declared.

View file

@ -351,6 +351,20 @@ var y = C.x;
'(D) → E');
}
void test_inferredType_instanceField_conditional_genericFunctions() {
createLinker('''
class C {
final f = true ? <T>(T t) => 0 : <T>(T t) => 1;
}
''');
LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
library.libraryCycleForLink.ensureLinked();
ClassElementForLink_Class cls = library.getContainedName('C');
expect(cls.fields, hasLength(1));
var field = cls.fields[0];
expect(field.type.toString(), '(<bottom>) → dynamic');
}
void test_inferredType_instanceField_dynamic() {
createLinker('''
var x;