2012-08-16 17:05:19 +00:00
|
|
|
// Copyright (c) 2012, 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.
|
|
|
|
// Dart test program for constructors and initializers.
|
|
|
|
|
2013-10-31 14:39:17 +00:00
|
|
|
import "package:expect/expect.dart";
|
|
|
|
|
2012-08-16 17:05:19 +00:00
|
|
|
// Test 'expression as Type' casts.
|
|
|
|
|
|
|
|
class C {
|
|
|
|
final int foo = 42;
|
2013-10-31 14:39:17 +00:00
|
|
|
|
|
|
|
int val = 0;
|
2017-03-23 19:40:21 +00:00
|
|
|
void inc() {
|
|
|
|
++val;
|
|
|
|
}
|
2012-08-16 17:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class D extends C {
|
|
|
|
final int bar = 37;
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2013-10-31 15:06:57 +00:00
|
|
|
C oc = new C();
|
|
|
|
D od = new D();
|
2012-08-16 17:05:19 +00:00
|
|
|
|
2017-08-04 23:52:11 +00:00
|
|
|
Expect.throwsNoSuchMethodError(() => (oc as dynamic).bar);
|
2012-08-16 17:05:19 +00:00
|
|
|
|
2013-10-31 14:39:17 +00:00
|
|
|
// Casts should always evaluate the left-hand side, if only for its effects.
|
|
|
|
oc.inc() as dynamic;
|
|
|
|
Expect.equals(1, oc.val);
|
|
|
|
oc.inc() as Object;
|
|
|
|
Expect.equals(2, oc.val);
|
|
|
|
}
|