Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(530)

Unified Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 1966783003: First steps toward AST-based type inference involving closures. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/src/summary/summary_common.dart
diff --git a/pkg/analyzer/test/src/summary/summary_common.dart b/pkg/analyzer/test/src/summary/summary_common.dart
index 2246695d205a267e1142e2c3abb3870d51855965..0abc4de5b35a2dc00b3b77ee348220cf74c5f111 100644
--- a/pkg/analyzer/test/src/summary/summary_common.dart
+++ b/pkg/analyzer/test/src/summary/summary_common.dart
@@ -1772,6 +1772,57 @@ class C<T> {
strings: ['T']);
}
+ test_constExpr_functionExpression_asArgument() {
+ // Even though function expressions are not allowed in constant
+ // declarations, they might occur due to erroneous code, so make sure they
+ // function correctly.
+ UnlinkedVariable variable = serializeVariableText('''
+const v = foo(5, () => 42);
+foo(a, b) {}
+''');
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
+ UnlinkedConstOperation.pushInt,
+ UnlinkedConstOperation.pushLocalFunctionReference,
+ UnlinkedConstOperation.invokeMethodRef
+ ], ints: [
+ 5,
+ 0,
+ 0,
+ 0,
+ 2
+ ], referenceValidators: [
+ (EntityRef r) => checkTypeRef(r, null, null, 'foo',
+ expectedKind: ReferenceKind.topLevelFunction)
+ ]);
+ }
+
+ test_constExpr_functionExpression_asArgument_multiple() {
+ // Even though function expressions are not allowed in constant
+ // declarations, they might occur due to erroneous code, so make sure they
+ // function correctly.
+ UnlinkedVariable variable = serializeVariableText('''
+const v = foo(5, () => 42, () => 43);
+foo(a, b, c) {}
+''');
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
+ UnlinkedConstOperation.pushInt,
+ UnlinkedConstOperation.pushLocalFunctionReference,
+ UnlinkedConstOperation.pushLocalFunctionReference,
+ UnlinkedConstOperation.invokeMethodRef
+ ], ints: [
+ 5,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ 3
+ ], referenceValidators: [
+ (EntityRef r) => checkTypeRef(r, null, null, 'foo',
+ expectedKind: ReferenceKind.topLevelFunction)
+ ]);
+ }
+
test_constExpr_invokeConstructor_generic_named() {
UnlinkedVariable variable = serializeVariableText('''
class C<K, V> {
@@ -6804,11 +6855,13 @@ foo(a, b) {}
''');
_assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.pushInt,
- UnlinkedConstOperation.pushNull,
+ UnlinkedConstOperation.pushLocalFunctionReference,
UnlinkedConstOperation.invokeMethodRef
], ints: [
5,
0,
+ 0,
+ 0,
2
], referenceValidators: [
(EntityRef r) => checkTypeRef(r, null, null, 'foo',
@@ -6816,6 +6869,33 @@ foo(a, b) {}
]);
}
+ test_expr_functionExpression_asArgument_multiple() {
+ if (skipNonConstInitializers) {
+ return;
+ }
+ UnlinkedVariable variable = serializeVariableText('''
+final v = foo(5, () => 42, () => 43);
+foo(a, b, c) {}
+''');
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
+ UnlinkedConstOperation.pushInt,
+ UnlinkedConstOperation.pushLocalFunctionReference,
+ UnlinkedConstOperation.pushLocalFunctionReference,
+ UnlinkedConstOperation.invokeMethodRef
+ ], ints: [
+ 5,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ 3
+ ], referenceValidators: [
+ (EntityRef r) => checkTypeRef(r, null, null, 'foo',
+ expectedKind: ReferenceKind.topLevelFunction)
+ ]);
+ }
+
test_expr_functionExpression_withBlockBody() {
if (skipNonConstInitializers) {
return;
@@ -6824,7 +6904,9 @@ foo(a, b) {}
final v = () { return 42; };
''');
_assertUnlinkedConst(variable.constExpr,
- isValidConst: false, operators: [UnlinkedConstOperation.pushNull]);
+ isValidConst: false,
+ operators: [UnlinkedConstOperation.pushLocalFunctionReference],
+ ints: [0, 0]);
}
test_expr_functionExpression_withExpressionBody() {
@@ -6835,7 +6917,9 @@ final v = () { return 42; };
final v = () => 42;
''');
_assertUnlinkedConst(variable.constExpr,
- isValidConst: false, operators: [UnlinkedConstOperation.pushNull]);
+ isValidConst: false,
+ operators: [UnlinkedConstOperation.pushLocalFunctionReference],
+ ints: [0, 0]);
}
test_expr_functionExpressionInvocation_withBlockBody() {
@@ -8948,8 +9032,8 @@ void set f(value) {}''';
// ids should be reused.
addNamedSource('/a.dart', 'part of foo; final v = 0;');
serializeLibraryText('library foo; part "a.dart"; final w = 0;');
- expect(unlinkedUnits[0].variables[0].propagatedTypeSlot, 1);
- expect(unlinkedUnits[1].variables[0].propagatedTypeSlot, 1);
+ expect(unlinkedUnits[1].variables[0].propagatedTypeSlot,
+ unlinkedUnits[0].variables[0].propagatedTypeSlot);
}
test_syntheticFunctionType_genericClosure() {

Powered by Google App Engine
This is Rietveld 408576698