Skip to content

Commit

Permalink
[wildcard-variables] Tests with this and super initializing formal pa…
Browse files Browse the repository at this point in the history
…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
kallentu authored and Commit Queue committed May 29, 2024
1 parent 28da71b commit 429f3e1
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
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._);
}
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
}
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
}
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;
}
}

0 comments on commit 429f3e1

Please sign in to comment.