[anonymous methods] Test that super can't be used in parameterless anonymous methods.
Change-Id: Icf5ccff095e42a6e8c151b31c741aec96a6a6964 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497061 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
dff95e77a4
commit
46e2cfe3fd
@@ -0,0 +1,113 @@
|
||||
// Copyright (c) 2026, 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.
|
||||
|
||||
// SharedOptions=--enable-experiment=anonymous-methods
|
||||
|
||||
// This test verifies that `super` can't be used inside a parameterless
|
||||
// anonymous method.
|
||||
//
|
||||
// Note that whereas the analyzer has just a single representation of `super`,
|
||||
// the CFE has a large number of them. So this test tries to exercise each CFE
|
||||
// representation.
|
||||
|
||||
class Base {
|
||||
int i = 0;
|
||||
operator[](int index) => null;
|
||||
operator[]=(int index, Object? value) {}
|
||||
void m() {}
|
||||
}
|
||||
|
||||
class Derived extends Base {
|
||||
test() {
|
||||
// CFE AST node: IfNullSuperIndexSet
|
||||
this.{
|
||||
super[0] ??= 1;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
};
|
||||
|
||||
// CFE AST node: SuperIndexSet
|
||||
this.{
|
||||
super[0] = 1;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
};
|
||||
|
||||
// CFE AST node: SuperIncDec
|
||||
this.{
|
||||
super.i++;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
++super.i;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
};
|
||||
|
||||
// CFE AST node: SuperMethodInvocation
|
||||
this.{
|
||||
super.m();
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
};
|
||||
|
||||
// CFE AST node: CompoundSuperIndexSet
|
||||
this.{
|
||||
super[0] += 1;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
};
|
||||
|
||||
// CFE AST node: SuperPropertySet
|
||||
this.{
|
||||
super.i = 0;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
};
|
||||
|
||||
// CFE AST node: SuperPropertyGet
|
||||
this.{
|
||||
super.i;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
mixin Mixin on Base {
|
||||
test() {
|
||||
// CFE AST node: AbstractSuperPropertyGet
|
||||
this.{
|
||||
super.i;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
};
|
||||
|
||||
// CFE AST node: AbstractSuperMethodInvocation
|
||||
this.{
|
||||
super.m();
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
};
|
||||
|
||||
// CFE AST node: AbstractSuperPropertySet
|
||||
this.{
|
||||
super.i = 0;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
main() {}
|
||||
@@ -0,0 +1,93 @@
|
||||
// Copyright (c) 2026, 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.
|
||||
|
||||
// SharedOptions=--enable-experiment=anonymous-methods
|
||||
|
||||
// This test verifies that `super` can't be used inside a parameterless
|
||||
// anonymous method.
|
||||
//
|
||||
// Note that whereas the analyzer has just a single representation of `super`,
|
||||
// the CFE has a large number of them. So this test tries to exercise each CFE
|
||||
// representation.
|
||||
|
||||
class Base {
|
||||
int i = 0;
|
||||
operator[](int index) => null;
|
||||
operator[]=(int index, Object? value) {}
|
||||
void m() {}
|
||||
}
|
||||
|
||||
class Derived extends Base {
|
||||
test() {
|
||||
// CFE AST node: IfNullSuperIndexSet
|
||||
this.=> super[0] ??= 1;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
|
||||
// CFE AST node: SuperIndexSet
|
||||
this.=> super[0] = 1;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
|
||||
// CFE AST node: SuperIncDec
|
||||
this.=> super.i++;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
this.=> ++super.i;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
|
||||
// CFE AST node: SuperMethodInvocation
|
||||
this.=> super.m();
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
|
||||
// CFE AST node: CompoundSuperIndexSet
|
||||
this.=> super[0] += 1;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
|
||||
// CFE AST node: SuperPropertySet
|
||||
this.=> super.i = 0;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
|
||||
// CFE AST node: SuperPropertyGet
|
||||
this.=> super.i;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
}
|
||||
}
|
||||
|
||||
mixin Mixin on Base {
|
||||
test() {
|
||||
// CFE AST node: AbstractSuperPropertyGet
|
||||
this.=> super.i;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
|
||||
// CFE AST node: AbstractSuperMethodInvocation
|
||||
this.=> super.m();
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
|
||||
// CFE AST node: AbstractSuperPropertySet
|
||||
this.=> super.i = 0;
|
||||
// ^^^^^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
}
|
||||
}
|
||||
|
||||
main() {}
|
||||
Reference in New Issue
Block a user