mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:09:49 +00:00
5642199dd0
Change-Id: I35bb926e53e92fd02e264fb5b14feadf063fb8db Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/257961 Reviewed-by: Michael Thomsen <mit@google.com> Commit-Queue: Lasse Nielsen <lrn@google.com>
41 lines
1.5 KiB
Dart
41 lines
1.5 KiB
Dart
// Copyright (c) 2013, 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 that parameter default values are disallowed in a redirecting factory.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
class A {
|
|
A(this.a, [this.b = 0]);
|
|
factory A.f(int a) = A;
|
|
factory A.g(int a, [int b = 0]) = A;
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR
|
|
// ^
|
|
// [cfe] Can't have a default value here because any default values of 'A' would be used instead.
|
|
factory A.h(int a, {int b = 0}) = A;
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR
|
|
// ^
|
|
// [cfe] Can't have a default value here because any default values of 'A' would be used instead.
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.REDIRECT_TO_INVALID_FUNCTION_TYPE
|
|
// [cfe] The constructor function type 'A Function(int, [int])' isn't a subtype of 'A Function(int, {int b})'.
|
|
|
|
int a;
|
|
int b;
|
|
}
|
|
|
|
main() {
|
|
var x = new A.f(42);
|
|
Expect.equals(x.a, 42);
|
|
Expect.equals(x.b, 0);
|
|
|
|
var y = new A.f(42, 43);
|
|
// ^^
|
|
// [analyzer] COMPILE_TIME_ERROR.EXTRA_POSITIONAL_ARGUMENTS
|
|
// ^^^^^^^^
|
|
// [cfe] Too many positional arguments: 1 allowed, but 2 found.
|
|
}
|