mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:01:42 +00:00
Add some tests for calls with checks in strong mode.
Tests checks due to covariant subtyping, dynamic calls, and their interaction with tear-offs. The tests use explicit type annotations so they can run independently of frontend type inference. R=dmitryas@google.com, leafp@google.com Review-Url: https://codereview.chromium.org/2725563003 .
This commit is contained in:
parent
8166deb009
commit
ea4a89ba03
19
tests/language_strong/covariant_subtyping_tearoff1_test.dart
Normal file
19
tests/language_strong/covariant_subtyping_tearoff1_test.dart
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class Foo<T> {
|
||||
dynamic method(T x) {}
|
||||
}
|
||||
|
||||
typedef dynamic TakeNum(num x);
|
||||
|
||||
main() {
|
||||
Foo<int> intFoo = new Foo<int>();
|
||||
Foo<num> numFoo = intFoo;
|
||||
TakeNum f = numFoo.method;
|
||||
Expect.throws(() => f(2.5));
|
||||
dynamic f2 = numFoo.method;
|
||||
Expect.throws(() => f2(2.5));
|
||||
}
|
26
tests/language_strong/covariant_subtyping_tearoff2_test.dart
Normal file
26
tests/language_strong/covariant_subtyping_tearoff2_test.dart
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class Implementation {
|
||||
dynamic method(int x) {}
|
||||
}
|
||||
|
||||
abstract class Interface<T> {
|
||||
dynamic method(T x);
|
||||
}
|
||||
|
||||
class Subclass extends Implementation implements Interface<int> {}
|
||||
|
||||
typedef dynamic TakeNum(num x);
|
||||
|
||||
main() {
|
||||
Subclass subclass = new Subclass();
|
||||
Interface<int> intInterface = subclass;
|
||||
Interface<num> numInterface = intInterface;
|
||||
TakeNum f = numInterface.method;
|
||||
Expect.throws(() => f(2.5));
|
||||
dynamic f2 = f;
|
||||
Expect.throws(() => f2(2.5));
|
||||
}
|
39
tests/language_strong/covariant_subtyping_tearoff3_test.dart
Normal file
39
tests/language_strong/covariant_subtyping_tearoff3_test.dart
Normal file
|
@ -0,0 +1,39 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class Implementation {
|
||||
dynamic method(int x) {}
|
||||
}
|
||||
|
||||
abstract class Interface1<T> {
|
||||
dynamic method(T x);
|
||||
}
|
||||
|
||||
abstract class Interface2<T> {
|
||||
dynamic method(T x);
|
||||
}
|
||||
|
||||
class Subclass extends Implementation
|
||||
implements Interface1<int>, Interface2<int> {}
|
||||
|
||||
typedef dynamic TakeNum(num x);
|
||||
|
||||
main() {
|
||||
Subclass subclass = new Subclass();
|
||||
|
||||
Interface1<int> intInterface1 = subclass;
|
||||
Interface1<num> numInterface1 = intInterface1;
|
||||
TakeNum f1 = numInterface1.method;
|
||||
Expect.throws(() => f1(2.5));
|
||||
dynamic f1dynamic = f1;
|
||||
Expect.throws(() => f1dynamic(2.5));
|
||||
|
||||
Interface2<int> intInterface2 = subclass;
|
||||
Interface2<num> numInterface2 = intInterface2;
|
||||
TakeNum f2 = numInterface2.method;
|
||||
Expect.throws(() => f2(2.5));
|
||||
dynamic f2dynamic = f2;
|
||||
Expect.throws(() => f2dynamic(2.5));
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
import 'package:expect/expect.dart';
|
||||
|
||||
class Foo<T> {
|
||||
method(T x) {}
|
||||
dynamic method(T x) {}
|
||||
}
|
||||
|
||||
main() {
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
import 'package:expect/expect.dart';
|
||||
|
||||
class Implementation {
|
||||
method(int x) {}
|
||||
dynamic method(int x) {}
|
||||
}
|
||||
|
||||
abstract class Interface<T> {
|
||||
method(T x);
|
||||
dynamic method(T x);
|
||||
}
|
||||
|
||||
class Subclass extends Implementation implements Interface<int> {}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class Implementation {
|
||||
dynamic method(int x) {}
|
||||
}
|
||||
|
||||
abstract class Interface1<T> {
|
||||
dynamic method(T x);
|
||||
}
|
||||
|
||||
abstract class Interface2<T> {
|
||||
dynamic method(T x);
|
||||
}
|
||||
|
||||
class Subclass extends Implementation
|
||||
implements Interface1<int>, Interface2<int> {}
|
||||
|
||||
main() {
|
||||
Subclass subclass = new Subclass();
|
||||
|
||||
Interface1<int> intInterface1 = subclass;
|
||||
Interface1<num> numInterface1 = intInterface1;
|
||||
Expect.throws(() => numInterface1.method(2.5));
|
||||
|
||||
Interface2<int> intInterface2 = subclass;
|
||||
Interface2<num> numInterface2 = intInterface2;
|
||||
Expect.throws(() => numInterface2.method(2.5));
|
||||
}
|
18
tests/language_strong/tearoff_dynamic_test.dart
Normal file
18
tests/language_strong/tearoff_dynamic_test.dart
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class Foo {
|
||||
dynamic method(int x) {}
|
||||
}
|
||||
|
||||
main() {
|
||||
Foo foo = new Foo();
|
||||
|
||||
dynamic dynamicMethod1 = foo.method;
|
||||
Expect.throws(() => dynamicMethod1(2.5));
|
||||
|
||||
dynamic dynamicMethod2 = (foo as dynamic).method;
|
||||
Expect.throws(() => dynamicMethod2(2.5));
|
||||
}
|
Loading…
Reference in a new issue