0fcdc08e60
The new feature 'declaring constructors' will change the syntax such that it is an error for a non-declaring formal parameter declaration to have the modifier `final`, and it is an error to use `var` as a replacement for a type annotation (but the type annotation can still be omitted entirely). This CL removes those modifiers such that the tests will not start failing on things that aren't errors any more. Change-Id: Ie6628f66eca696b28900759d8234b814033b4027 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456740 Reviewed-by: Chloe Stefantsova <cstefantsova@google.com> Commit-Queue: Erik Ernst <eernst@google.com>
62 lines
1.7 KiB
Dart
62 lines
1.7 KiB
Dart
// 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.
|
|
// Test for instance field initializer expressions.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
class Cheese {
|
|
static const mild = 1;
|
|
static const stinky = 2;
|
|
|
|
// Instance fields with initializer expression.
|
|
String name = "";
|
|
var smell = mild;
|
|
|
|
Cheese() {
|
|
Expect.equals("", this.name);
|
|
Expect.equals(Cheese.mild, this.smell);
|
|
}
|
|
|
|
Cheese.initInBlock(String s) {
|
|
Expect.equals("", this.name);
|
|
Expect.equals(Cheese.mild, this.smell);
|
|
this.name = s;
|
|
}
|
|
|
|
Cheese.initFieldParam(this.name, this.smell) {}
|
|
|
|
// Test that static const field Cheese.mild is not shadowed
|
|
// by the parameter mild when compiling the field initializer
|
|
// for instance field smell.
|
|
Cheese.hideAndSeek(mild) : name = mild {
|
|
Expect.equals(mild, this.name);
|
|
Expect.equals(Cheese.mild, this.smell);
|
|
}
|
|
}
|
|
|
|
class HasNoExplicitConstructor {
|
|
String s = "Tilsiter";
|
|
}
|
|
|
|
main() {
|
|
var generic = new Cheese();
|
|
Expect.equals("", generic.name);
|
|
Expect.equals(Cheese.mild, generic.smell);
|
|
|
|
var gruyere = new Cheese.initInBlock("Gruyere");
|
|
Expect.equals("Gruyere", gruyere.name);
|
|
Expect.equals(Cheese.mild, gruyere.smell);
|
|
|
|
var munster = new Cheese.initFieldParam("Munster", Cheese.stinky);
|
|
Expect.equals("Munster", munster.name);
|
|
Expect.equals(Cheese.stinky, munster.smell);
|
|
|
|
var brie = new Cheese.hideAndSeek("Brie");
|
|
Expect.equals("Brie", brie.name);
|
|
Expect.equals(Cheese.mild, brie.smell);
|
|
|
|
var t = new HasNoExplicitConstructor();
|
|
Expect.equals("Tilsiter", t.s);
|
|
}
|