Files
sdk/tests/language/bad_constructor_test.dart
T
Asger Feldthaus 76442f9394 Fix language/bad_constructor_test in dartk and analyzer.
The test was incorrect because it did not declare that a static warning
was to be expected due to an unresolved reference to 'q'. The unresolved
reference has been removed as it has nothing to do with what it is
supposed to test.

The analyzer was incorrect in that a setter was reported to clash with
a constructor of the same name, but this failure was hidden by the
above issue. This has been fixed.

dartk inherited the issue (and its fix) from the analyzer, but some
additional error handling was needed in dartk to avoid crashing.

Closes https://github.com/dart-lang/sdk/issues/11576

BUG=
R=kmillikin@google.com, scheglov@google.com

Review-Url: https://codereview.chromium.org/2643693002 .
2017-01-19 13:10:32 +01:00

27 lines
751 B
Dart

// 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.
class A {
// Constructor may not be static.
static A(); /// 00: compile-time error
// Factory may not be static.
static factory A() { return null; } /// 01: compile-time error
// Named constructor may not conflict with names of methods and fields.
var m;
A.m() { m = 0; } /// 04: compile-time error
set q(var value) { m = 0; } // No name conflict with q=.
A.q(); /// 05: ok
A(); /// 05: ok
A.foo() : m = 0; /// 06: compile-time error
int foo(int a, int b) => a + b * m;
}
main() {
new A();
}