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

Unified Diff: tests/compiler/dart2js/expect_annotations_test.dart

Issue 875163004: Support [AssumeDynamic] and [TrustTypeAnnotations] in the inferrer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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
« no previous file with comments | « pkg/expect/lib/expect.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/expect_annotations_test.dart
diff --git a/tests/compiler/dart2js/expect_annotations_test.dart b/tests/compiler/dart2js/expect_annotations_test.dart
index ed8889ae13d7f74e6648f88f4fdce57a9097d94e..3ee1fdc6f96dd99fc14d948ea374cac7ed20b96c 100644
--- a/tests/compiler/dart2js/expect_annotations_test.dart
+++ b/tests/compiler/dart2js/expect_annotations_test.dart
@@ -8,6 +8,8 @@ import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/dart2jslib.dart';
import 'package:compiler/src/elements/elements.dart';
import 'package:compiler/src/js_backend/js_backend.dart';
+import 'package:compiler/src/types/types.dart';
+import 'type_mask_test_helper.dart';
import 'memory_compiler.dart';
const Map MEMORY_SOURCE_FILES = const {
@@ -28,12 +30,19 @@ int methodNoInlining(String arg) => arg.length;
@NoInlining() @TrustTypeAnnotations()
int methodNoInliningTrustTypeAnnotations(String arg) => arg.length;
+@AssumeDynamic() @TrustTypeAnnotations()
+int methodAssumeDynamicTrustTypeAnnotations(String arg) => arg.length;
+
+
void main(List<String> args) {
print(method(args[0]));
print(methodAssumeDynamic('foo'));
- print(methodTrustTypeAnnotations(null));
+ print(methodTrustTypeAnnotations(42));
+ print(methodTrustTypeAnnotations("fourtyTwo"));
print(methodNoInlining('bar'));
- print(methodNoInliningTrustTypeAnnotations(null));
+ print(methodNoInliningTrustTypeAnnotations(42));
+ print(methodNoInliningTrustTypeAnnotations("fourtyTwo"));
+ print(methodAssumeDynamicTrustTypeAnnotations(null));
}
"""
};
@@ -50,9 +59,25 @@ main() {
Expect.isNotNull(backend.annotations.expectAssumeDynamicClass,
'AssumeDynamicClass is unresolved.');
+ void testTypeMatch(FunctionElement function, TypeMask expectedParameterType,
+ TypeMask expectedReturnType, TypesInferrer inferrer) {
+ for (ParameterElement parameter in function.parameters) {
+ TypeMask type = inferrer.getTypeOfElement(parameter);
+ Expect.equals(expectedParameterType, simplify(type, compiler),
+ "$parameter");
+ }
+ if (expectedReturnType != null) {
+ TypeMask type = inferrer.getReturnTypeOfElement(function);
+ Expect.equals(expectedReturnType, simplify(type, compiler),
+ "$function");
+ }
+ }
+
void test(String name,
{bool expectNoInlining: false,
bool expectTrustTypeAnnotations: false,
+ TypeMask expectedParameterType: null,
+ TypeMask expectedReturnType: null,
bool expectAssumeDynamic: false}) {
Element method = compiler.mainApp.find(name);
Expect.isNotNull(method);
@@ -68,14 +93,35 @@ main() {
expectAssumeDynamic,
backend.annotations.assumeDynamic(method),
"Unexpected annotation of @AssumeDynamic on '$method'.");
+ TypesInferrer inferrer = compiler.typesTask.typesInferrer;
+ if (expectTrustTypeAnnotations && expectedParameterType != null) {
+ testTypeMatch(method, expectedParameterType, expectedReturnType,
+ inferrer);
+ } else if (expectAssumeDynamic) {
+ testTypeMatch(method, compiler.typesTask.dynamicType, null, inferrer);
+ }
}
+ TypeMask jsStringType = compiler.typesTask.stringType;
+ TypeMask jsIntType = compiler.typesTask.intType;
+ TypeMask coreStringType = new TypeMask.subtype(compiler.stringClass,
+ compiler.world);
+
test('method');
test('methodAssumeDynamic', expectAssumeDynamic: true);
- test('methodTrustTypeAnnotations', expectTrustTypeAnnotations: true);
+ test('methodTrustTypeAnnotations',
+ expectTrustTypeAnnotations: true,
+ expectedParameterType: jsStringType);
test('methodNoInlining', expectNoInlining: true);
test('methodNoInliningTrustTypeAnnotations',
expectNoInlining: true,
- expectTrustTypeAnnotations: true);
+ expectTrustTypeAnnotations: true,
+ expectedParameterType: jsStringType,
+ expectedReturnType: jsIntType);
+ test('methodAssumeDynamicTrustTypeAnnotations',
+ expectAssumeDynamic: true,
+ expectTrustTypeAnnotations: true,
+ expectedParameterType: coreStringType);
+
}));
}
« no previous file with comments | « pkg/expect/lib/expect.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698