mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 14:32:49 +00:00
6e637eb27f
If a final instance variable is initialized at the point of declaration, it is a runtime error if it is initialized again in a constructor’s initializer list or by an initializing formal. If any instance field is initialized more than once in the initializer list of a constructor, or by an initializing formal parameter, it is a compile time error. Adding a new test to cover the expected runtime error. Fixes issue 13335. R=regis@google.com Review URL: https://codereview.chromium.org//505033002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@39562 260f80e4-7a28-3924-810f-c04153c831b5
25 lines
728 B
Dart
25 lines
728 B
Dart
// Copyright (c) 2014, 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.
|
|
|
|
// Check that duplicate initialization of a final field is a runtime error.
|
|
|
|
|
|
class Class {
|
|
final f = 10;
|
|
|
|
Class(v) : f = v; /// 01: runtime error, static type warning
|
|
|
|
Class(this.f); /// 02: runtime error, static type warning
|
|
|
|
// If a field is initialized multiple times in the initializer
|
|
// list, it's a compile time error.
|
|
Class(this.f) : f = 0; /// 03: compile-time error
|
|
}
|
|
|
|
main() {
|
|
new Class(5); /// 01: continued
|
|
new Class(5); /// 02: continued
|
|
new Class(5); /// 03: continued
|
|
}
|