Chromium Code Reviews| Index: tests/language/src/TypeChecksInFactoryMethodTest.dart |
| diff --git a/tests/language/src/TypeChecksInFactoryMethodTest.dart b/tests/language/src/TypeChecksInFactoryMethodTest.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d865d6d886ab453c9d7e72cb2d2daa68da077a75 |
| --- /dev/null |
| +++ b/tests/language/src/TypeChecksInFactoryMethodTest.dart |
| @@ -0,0 +1,34 @@ |
| +// Copyright (c) 2011, 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. |
| +// VMOptions=--enable_type_checks --enable_asserts |
| +// Tests the type checking when passing code into closure from inside a factory method |
| + |
| +interface Foo<T> default Bar { |
| + Foo.from(); |
| +} |
| + |
| +class Bar<T> implements Foo<T> { |
| + Bar() {} |
| + |
| + factory Bar.from() { |
| + var func = (T arg) { T foo = arg; print(arg); }; |
| + // If T is not a string, runtime type checks should fail |
|
codefu
2011/12/22 16:13:50
And instance-of check should also fail.
|
| + func("Hello World!"); |
| + return new Bar<T>(); |
| + } |
| +} |
| + |
| +main() { |
| + Foo value; |
| + value = new Foo<String>.from(); |
| + |
| + bool gotError = false; |
| + |
| + try { |
| + value = new Foo<int>.from(); |
| + } catch (TypeError e) { |
| + gotError = true; |
| + } |
| + Expect.equals(true, gotError); |
| +} |