Add tests showing the async impact on function type checks

Change-Id: I8a59560dc18a8d491150d2c72287c2025e13beda
Reviewed-on: https://dart-review.googlesource.com/62061
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Johnni Winther 2018-06-26 08:11:04 +00:00 committed by commit-bot@chromium.org
parent 8e4d5c0a38
commit 2c98fb3c1d
6 changed files with 126 additions and 0 deletions

View file

@ -452,6 +452,31 @@ class MemberAnnotations<DataType> {
}
return _computedDataForEachFile[file];
}
String toString() {
StringBuffer sb = new StringBuffer();
sb.write('MemberAnnotations(');
String comma = '';
if (_computedDataForEachFile.isNotEmpty &&
(_computedDataForEachFile.length > 1 ||
_computedDataForEachFile.values.single.isNotEmpty)) {
sb.write('data:{');
_computedDataForEachFile.forEach((Uri uri, Map<Id, DataType> data) {
sb.write(comma);
sb.write('$uri:');
sb.write(data);
comma = ',';
});
sb.write('}');
}
if (globalData.isNotEmpty) {
sb.write(comma);
sb.write('global:');
sb.write(globalData);
}
sb.write(')');
return sb.toString();
}
}
typedef void Callback();

View file

@ -0,0 +1,26 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/*kernel.class: Class:*/
/*strong.class: Class:direct,explicit=[Class.T],implicit=[Class.T],needsArgs*/
/*omit.class: Class:needsArgs*/
class Class<T> {
method() {
var list = <T>[];
// With the `is dynamic Function(Object)` test in the async implementation
// the closure, with type `dynamic Function(T)`, needs its signature,
// requiring the need for type arguments on `Class`.
//
// This happens because the closure is thought as possibly going to the
// async.errorHandler callback.
list.forEach(
/*strong.needsSignature*/
/*omit.needsSignature*/
(x) => print(x));
}
}
main() async {
new Class<int>().method();
}

View file

@ -0,0 +1,22 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/*kernel.class: Class:*/
/*strong.class: Class:direct,explicit=[Class.T],implicit=[Class.T],needsArgs*/
/*omit.class: Class:*/
class Class<T> {
method() {
var list = <T>[];
// If any method was `async`, this would have triggered the need for type
// arguments on `Class`. See the 'async_foreach.dart' test.
list.forEach(
/*strong.needsSignature*/
/*omit.*/
(x) => print(x));
}
}
main() {
new Class<int>().method();
}

View file

@ -0,0 +1,18 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
main() async {
// With the `is dynamic Function(Object,StackTrace)` test in the async
// implementation the closure, with type `dynamic Function(dynamic, dynamic)`,
// needs its signature.
//
// This happens because the closure is thought as possibly going to the
// async.errorHandler callback.
/*kernel.*/
/*strong.needsSignature*/
/*omit.needsSignature*/
local(object, stacktrace) => null;
return local;
}

View file

@ -0,0 +1,14 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
main() {
// If any method was `async`, this would have triggered the need for the
// signature on this closure. See the 'async_local.dart' test.
/*kernel.*/
/*strong.*/
/*omit.*/
local(object, stacktrace) => null;
return local;
}

View file

@ -0,0 +1,21 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/*kernel.class: Class:*/
/*strong.class: Class:explicit=[Class<int>],needsArgs*/
/*omit.class: Class:*/
class Class<T> {}
main() async {
// Despite the `is dynamic Function(Object,StackTrace)` test in the async
// implementation the closure, with type
// `dynamic Function(dynamic, Class<int>)`, is not a potential subtype and
// therefore doesn't need its signature.
/*kernel.*/
/*strong.needsSignature*/
/*omit.*/
local(object, Class<int> stacktrace) => null;
return local;
}