[wildcard-variables] Test non-binding behaviour with top-level declarations.

Added a little section for late wildcard variables too.

This CL tests mixing top-level wildcard declarations with local wildcard declarations and the non-shadowing, non-binding behaviour.

Bug: https://github.com/dart-lang/sdk/issues/55652
Change-Id: I72e7cfb1b2d80a3934af355579c36252881cf3fb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367241
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
This commit is contained in:
Kallen Tu 2024-05-21 22:15:11 +00:00 committed by Commit Queue
parent ffbbdb5a10
commit bd8f87d477
5 changed files with 154 additions and 0 deletions

View file

@ -16,4 +16,10 @@ void main() {
int _;
final _;
late int _;
late int _ = 2;
late final int _;
late final int _ = 2;
}

View file

@ -0,0 +1,50 @@
// 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.
// Test the interactions between a wildcard class members, which are binding,
// with local non-binding wildcard variables.
// SharedOptions=--enable-experiment=wildcard-variables
import 'package:expect/expect.dart';
void main() {
InstanceMember().member();
StaticMember().member();
}
class InstanceMember {
var _ = 2;
void member<_, _>() {
int _ = _;
int _ = 2;
const _ = 2;
int _() => 2;
_ = 3;
Expect.equals(3, _);
int _() => 2;
int foo<_>([int _ = 5]) => _;
Expect.equals(3, foo());
}
}
class StaticMember {
static const _ = 2;
void member<_, _>() {
int _ = _;
int _ = 2;
const _ = 2;
const _ = _ - 1;
int _() => 2;
_ = 3;
Expect.equals(3, _);
int foo<_>([int _ = _ + 1]) => _;
Expect.equals(3, foo());
}
}

View file

@ -0,0 +1,28 @@
// 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.
// Test the interactions between a wildcard top-level function, which is
// binding, with local non-binding wildcard variables.
// SharedOptions=--enable-experiment=wildcard-variables
import 'package:expect/expect.dart';
int _(int _) => 2;
void main() {
int _ = 1;
const _ = 1;
int _() => 1;
Expect.equals(2, _(1));
}
class Clas<_> {
void member<_>() {
int _ = 1;
const _ = 1;
int _() => 1;
Expect.equals(2, _(1));
}
}

View file

@ -0,0 +1,36 @@
// 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.
// Test the interactions between a wildcard typedef, which is binding, with
// local non-binding wildcard variables.
// SharedOptions=--enable-experiment=wildcard-variables
import 'package:expect/expect.dart';
typedef _ = Type;
_ function<_ extends _>([_ _ = _]) => _;
void main<_ extends _>() {
_ _ = _;
final _ _ = _;
const _ _ = _;
_ foo<_ extends _>([_ _ = int]) => _;
_ bar<_ extends _>([_ _ = _]) => int;
Expect.type<Type>(foo());
Expect.type<int>(bar());
}
class CConst {
static const _ = 42;
void member<_>() {
var _ = _;
final _ = _;
const _ = _;
int _() => 1;
int foo<_>([String _ = "$_"]) => _;
_ = foo();
}
}

View file

@ -0,0 +1,34 @@
// 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.
// Test the interactions between a wildcard top-level variable, which is
// binding, with local non-binding wildcard variables.
// SharedOptions=--enable-experiment=wildcard-variables
import 'package:expect/expect.dart';
var _ = 2;
void main() {
Clas().member();
int _ = _;
int _ = 2;
_ = 3;
Expect.equals(3, _);
}
class Clas<_> {
void member<_>() {
int _ = _;
int _ = 2;
Expect.equals(2, _);
_ = 4;
Expect.equals(4, _);
int foo<_>([int _ = 5]) => _;
Expect.equals(4, foo());
}
}