Fix for type inference from instance creation arguments.

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

Change-Id: I0e8386f2a7b3e6d034350a21e474fc1a297c0120
Reviewed-on: https://dart-review.googlesource.com/48762
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2018-03-29 19:44:20 +00:00 committed by commit-bot@chromium.org
parent 055dfad887
commit 3306aabd82
2 changed files with 42 additions and 1 deletions

View file

@ -5233,7 +5233,11 @@ class _UnitResynthesizer extends UnitResynthesizer with UnitResynthesizerMixin {
DartType buildTypeForClassInfo(
info, int numTypeArguments, DartType Function(int i) getTypeArgument) {
ClassElementForLink class_ = info.element;
if (numTypeArguments == 0) return class_.typeWithDefaultBounds;
if (numTypeArguments == 0) {
DartType type = class_.typeWithDefaultBounds;
_typesWithImplicitArguments[type] = true;
return type;
}
return class_.buildType(getTypeArgument, const []);
}

View file

@ -6660,6 +6660,43 @@ D<T> f<T>() {}
}
}
test_infer_instanceCreation_fromArguments() async {
var library = await checkLibrary('''
class A {}
class B extends A {}
class S<T extends A> {
S(T _);
}
var s = new S(new B());
''');
if (isStrongMode) {
checkElementText(library, '''
class A {
}
class B extends A {
}
class S<T extends A> {
S(T _);
}
S<B> s;
''');
} else {
checkElementText(library, '''
class A {
}
class B extends A {
}
class S<T extends A> {
S(T _);
}
dynamic s;
''');
}
}
test_infer_property_set() async {
var library = await checkLibrary('''
class A {