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

Side by Side Diff: test/checker/inferred_type_test.dart

Issue 1317933005: Some preliminary support for quasi-generics (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Reformat Created 5 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Tests for type inference. 5 /// Tests for type inference.
6 library dev_compiler.test.inferred_type_test; 6 library dev_compiler.test.inferred_type_test;
7 7
8 import 'package:test/test.dart'; 8 import 'package:test/test.dart';
9 9
10 import '../testing.dart'; 10 import '../testing.dart';
(...skipping 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 }, 1589 },
1590 inferDownwards: true); 1590 inferDownwards: true);
1591 1591
1592 testChecker('inferred initializing formal checks default value', { 1592 testChecker('inferred initializing formal checks default value', {
1593 '/main.dart': ''' 1593 '/main.dart': '''
1594 class Foo { 1594 class Foo {
1595 var x = 1; 1595 var x = 1;
1596 Foo([this.x = /*severe:StaticTypeError*/"1"]); 1596 Foo([this.x = /*severe:StaticTypeError*/"1"]);
1597 }''' 1597 }'''
1598 }); 1598 });
1599
1600 group('quasi-generics', () {
1601 testChecker('dart:math min/max', {
1602 '/main.dart': '''
1603 import 'dart:math';
1604
1605 void printInt(int x) => print(x);
1606 void printDouble(double x) => print(x);
1607
1608 num myMax(num x, num y) => max(x, y);
1609
1610 main() {
1611 // Okay if static types match.
1612 printInt(max(1, 2));
1613 printInt(min(1, 2));
1614 printDouble(max(1.0, 2.0));
1615 printDouble(min(1.0, 2.0));
1616
1617 // No help for user-defined functions from num->num->num.
1618 printInt(/*info:DownCastImplicit*/myMax(1, 2));
1619 printInt(myMax(1, 2) as int);
1620
1621 // Mixing int and double means return type is num.
1622 printInt(/*info:DownCastImplicit*/max(1, 2.0));
1623 printInt(/*info:DownCastImplicit*/min(1, 2.0));
1624 printDouble(/*info:DownCastImplicit*/max(1, 2.0));
1625 printDouble(/*info:DownCastImplicit*/min(1, 2.0));
1626
1627 // Types other than int and double are not accepted.
1628 printInt(
1629 /*info:DownCastImplicit*/min(
1630 /*severe:StaticTypeError*/"hi",
1631 /*severe:StaticTypeError*/"there"));
1632 }
1633 '''
1634 });
1635
1636 testChecker('Iterable and Future', {
1637 '/main.dart': '''
1638 import 'dart:async';
1639
1640 Future<int> make(int x) => (/*info:InferredTypeAllocation*/new Future(() => x));
1641
1642 main() {
1643 Iterable<Future<int>> list = <int>[1, 2, 3].map(make);
1644 Future<List<int>> results = Future.wait(list);
1645 Future<String> results2 = results.then((List<int> list)
1646 => list.fold('', (String x, int y) => x + y.toString()));
1647 }
1648 '''
1649 });
1650 });
1599 } 1651 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698