From 46e2cfe3fd92e4293eeb9bf43635ca642c3d935c Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 22 Apr 2026 07:19:04 -0700 Subject: [PATCH] [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 Reviewed-by: Erik Ernst --- .../block/super_error_test.dart | 113 ++++++++++++++++++ .../expression/super_error_test.dart | 93 ++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 tests/language/anonymous_methods/block/super_error_test.dart create mode 100644 tests/language/anonymous_methods/expression/super_error_test.dart diff --git a/tests/language/anonymous_methods/block/super_error_test.dart b/tests/language/anonymous_methods/block/super_error_test.dart new file mode 100644 index 00000000000..530856a34dc --- /dev/null +++ b/tests/language/anonymous_methods/block/super_error_test.dart @@ -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() {} diff --git a/tests/language/anonymous_methods/expression/super_error_test.dart b/tests/language/anonymous_methods/expression/super_error_test.dart new file mode 100644 index 00000000000..f9686fef99a --- /dev/null +++ b/tests/language/anonymous_methods/expression/super_error_test.dart @@ -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() {}