-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wildcard-variables] Tests with this and super initializing formal pa…
…rameters. Next set of tests with initializing formal parameters. Bug: #55652 Change-Id: I1d8ff69249ad75c8065a159c333f91b62b30f769 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367822 Commit-Queue: Kallen Tu <kallentu@google.com> Reviewed-by: Lasse Nielsen <lrn@google.com>
- Loading branch information
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
tests/language/wildcard_variables/initializing_formal_parameters/super_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
// `super._` will pass on the given actual argument to the corresponding | ||
// superconstructor parameter. | ||
|
||
// SharedOptions=--enable-experiment=wildcard-variables | ||
|
||
import 'package:expect/expect.dart'; | ||
|
||
void main() { | ||
var c = C(1); | ||
Expect.equals(1, c._); | ||
|
||
var cWithPositional = C.withPositional(1, 100); | ||
Expect.equals(1, cWithPositional._); | ||
|
||
var multipleSuperParameters = MultipleSuperParameters(1, 2, 3); | ||
Expect.equals(1, multipleSuperParameters._); | ||
Expect.equals(2, multipleSuperParameters.x); | ||
Expect.equals(3, multipleSuperParameters.y); | ||
} | ||
|
||
class B<_> { | ||
var _; | ||
|
||
B(this._); | ||
B.withPositional(this._, _); | ||
} | ||
|
||
class C<_> extends B { | ||
C(super._); | ||
C.superAndPositional(super._, _); | ||
} | ||
|
||
class MultipleParameters { | ||
final int x, y; | ||
MultipleParameters(this.x, this.y); | ||
} | ||
|
||
class MultipleSuperParameters extends MultipleParameters { | ||
final int _; | ||
MultipleSuperParameters(this._, super._, super._); | ||
} |
27 changes: 27 additions & 0 deletions
27
...wildcard_variables/initializing_formal_parameters/this_initializer_access_error_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
// It's an error for `_` to be accessed inside an initializer list. | ||
|
||
// SharedOptions=--enable-experiment=wildcard-variables | ||
|
||
class C { | ||
var _; | ||
var other; | ||
|
||
C(this._) : other = _; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class CWithTypeParameter<_> { | ||
var _; | ||
var other; | ||
|
||
CWithTypeParameter(this._) : other = _; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
21 changes: 21 additions & 0 deletions
21
...ldcard_variables/initializing_formal_parameters/this_initializer_multiple_error_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
// It's an error to have two initializing formals named `_`. | ||
|
||
// SharedOptions=--enable-experiment=wildcard-variables | ||
|
||
class C { | ||
var _; | ||
|
||
C(this._, this._); | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
C.named(this._, this._); | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/language/wildcard_variables/initializing_formal_parameters/this_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
// A positional initializing formal named `_` does still initialize a field | ||
// named `_`, and you can still have a field with that name. | ||
|
||
// SharedOptions=--enable-experiment=wildcard-variables | ||
|
||
import 'package:expect/expect.dart'; | ||
|
||
void main() { | ||
var c = C(1); | ||
Expect.equals(1, c._); | ||
|
||
var cWithPositional = C.withPositional(1, 100); | ||
Expect.equals(1, cWithPositional._); | ||
|
||
var cWithBody = C.withBody(1); | ||
Expect.equals(200, cWithBody._); | ||
} | ||
|
||
class C<_> { | ||
var _; | ||
|
||
C(this._); | ||
C.withPositional(this._, _); | ||
C.withBody(this._) { | ||
_ = 200; | ||
} | ||
} |