diff --git a/pkg/analyzer/test/src/dart/resolution/class_test.dart b/pkg/analyzer/test/src/dart/resolution/class_test.dart index 8a1783780e6c..53ff0e9345f8 100644 --- a/pkg/analyzer/test/src/dart/resolution/class_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/class_test.dart @@ -478,450 +478,6 @@ class B extends A { [CompileTimeErrorCode.CONFLICTING_METHOD_AND_FIELD]); } - test_error_conflictingStaticAndInstance_inClass_getter_getter() async { - addTestFile(r''' -class C { - static int get foo => 0; - int get foo => 0; -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inClass_getter_method() async { - addTestFile(r''' -class C { - static int get foo => 0; - void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inClass_getter_setter() async { - addTestFile(r''' -class C { - static int get foo => 0; - set foo(_) {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inClass_method_getter() async { - addTestFile(r''' -class C { - static void foo() {} - int get foo => 0; -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inClass_method_method() async { - addTestFile(r''' -class C { - static void foo() {} - void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inClass_method_setter() async { - addTestFile(r''' -class C { - static void foo() {} - set foo(_) {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inClass_setter_getter() async { - addTestFile(r''' -class C { - static set foo(_) {} - int get foo => 0; -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inClass_setter_method() async { - addTestFile(r''' -class C { - static set foo(_) {} - void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inClass_setter_setter() async { - addTestFile(r''' -class C { - static set foo(_) {} - set foo(_) {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inInterface_getter_getter() async { - addTestFile(r''' -class A { - int get foo => 0; -} -abstract class B implements A { - static int get foo => 0; -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inInterface_getter_method() async { - addTestFile(r''' -class A { - int get foo => 0; -} -abstract class B implements A { - static void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inInterface_getter_setter() async { - addTestFile(r''' -class A { - set foo(_) {} -} -abstract class B implements A { - static int get foo => 0; -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inInterface_method_getter() async { - addTestFile(r''' -class A { - int get foo => 0; -} -abstract class B implements A { - static void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inInterface_method_method() async { - addTestFile(r''' -class A { - void foo() {} -} -abstract class B implements A { - static void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inInterface_method_setter() async { - addTestFile(r''' -class A { - set foo(_) {} -} -abstract class B implements A { - static void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inInterface_setter_method() async { - addTestFile(r''' -class A { - void foo() {} -} -abstract class B implements A { - static set foo(_) {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inInterface_setter_setter() async { - addTestFile(r''' -class A { - set foo(_) {} -} -abstract class B implements A { - static set foo(_) {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inMixin_getter_getter() async { - addTestFile(r''' -class A { - int get foo => 0; -} -class B extends Object with A { - static int get foo => 0; -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inMixin_getter_method() async { - addTestFile(r''' -class A { - int get foo => 0; -} -class B extends Object with A { - static void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inMixin_getter_setter() async { - addTestFile(r''' -class A { - set foo(_) {} -} -class B extends Object with A { - static int get foo => 0; -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inMixin_method_getter() async { - addTestFile(r''' -class A { - int get foo => 0; -} -class B extends Object with A { - static void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inMixin_method_method() async { - addTestFile(r''' -class A { - void foo() {} -} -class B extends Object with A { - static void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inMixin_method_setter() async { - addTestFile(r''' -class A { - set foo(_) {} -} -class B extends Object with A { - static void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inMixin_setter_method() async { - addTestFile(r''' -class A { - void foo() {} -} -class B extends Object with A { - static set foo(_) {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inMixin_setter_setter() async { - addTestFile(r''' -class A { - set foo(_) {} -} -class B extends Object with A { - static set foo(_) {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inSuper_getter_getter() async { - addTestFile(r''' -class A { - int get foo => 0; -} -class B extends A { - static int get foo => 0; -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inSuper_getter_method() async { - addTestFile(r''' -class A { - int get foo => 0; -} -class B extends A { - static void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inSuper_getter_setter() async { - addTestFile(r''' -class A { - set foo(_) {} -} -class B extends A { - static int get foo => 0; -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inSuper_method_getter() async { - addTestFile(r''' -class A { - int get foo => 0; -} -class B extends A { - static void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inSuper_method_method() async { - addTestFile(r''' -class A { - void foo() {} -} -class B extends A { - static void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inSuper_method_setter() async { - addTestFile(r''' -class A { - set foo(_) {} -} -class B extends A { - static void foo() {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inSuper_setter_method() async { - addTestFile(r''' -class A { - void foo() {} -} -class B extends A { - static set foo(_) {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - - test_error_conflictingStaticAndInstance_inSuper_setter_setter() async { - addTestFile(r''' -class A { - set foo(_) {} -} -class B extends A { - static set foo(_) {} -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - test_error_duplicateConstructorDefault() async { addTestFile(r''' class C { diff --git a/pkg/analyzer/test/src/dart/resolution/enum_test.dart b/pkg/analyzer/test/src/dart/resolution/enum_test.dart index c73159636645..a7f3654eed13 100644 --- a/pkg/analyzer/test/src/dart/resolution/enum_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/enum_test.dart @@ -20,17 +20,6 @@ class EnumDriverResolutionTest extends DriverResolutionTest with EnumResolutionMixin {} mixin EnumResolutionMixin implements ResolutionTest { - test_error_conflictingStaticAndInstance_index() async { - addTestFile(r''' -enum E { - a, index -} -'''); - await resolveTestFile(); - assertTestErrorsWithCodes( - [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE]); - } - test_inference_listLiteral() async { addTestFile(r''' enum E1 {a, b} diff --git a/pkg/analyzer/test/src/dart/resolution/mixin_test.dart b/pkg/analyzer/test/src/dart/resolution/mixin_test.dart index 3165b966945d..827c61bfdff6 100644 --- a/pkg/analyzer/test/src/dart/resolution/mixin_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/mixin_test.dart @@ -234,313 +234,6 @@ class D = Object with M2; '''); } - test_error_conflictingStaticAndInstance_inClass_getter_getter() async { - await assertErrorsInCode(r''' -mixin M { - static int get foo => 0; - int get foo => 0; -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 27, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inClass_getter_method() async { - await assertErrorsInCode(r''' -mixin M { - static int get foo => 0; - void foo() {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 27, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inClass_getter_setter() async { - await assertErrorsInCode(r''' -mixin M { - static int get foo => 0; - set foo(_) {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 27, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inClass_method_getter() async { - await assertErrorsInCode(r''' -mixin M { - static void foo() {} - int get foo => 0; -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 24, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inClass_method_method() async { - await assertErrorsInCode(r''' -mixin M { - static void foo() {} - void foo() {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 24, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inClass_method_setter() async { - await assertErrorsInCode(r''' -mixin M { - static void foo() {} - set foo(_) {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 24, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inClass_setter_getter() async { - await assertErrorsInCode(r''' -mixin M { - static set foo(_) {} - int get foo => 0; -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 23, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inClass_setter_method() async { - await assertErrorsInCode(r''' -mixin M { - static set foo(_) {} - void foo() {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 23, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inClass_setter_setter() async { - await assertErrorsInCode(r''' -mixin M { - static set foo(_) {} - set foo(_) {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 23, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inConstraint_getter_getter() async { - await assertErrorsInCode(r''' -class A { - int get foo => 0; -} -mixin M on A { - static int get foo => 0; -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 64, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inConstraint_getter_method() async { - await assertErrorsInCode(r''' -class A { - int get foo => 0; -} -mixin M on A { - static void foo() {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 61, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inConstraint_getter_setter() async { - await assertErrorsInCode(r''' -class A { - set foo(_) {} -} -mixin M on A { - static int get foo => 0; -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 60, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inConstraint_method_getter() async { - await assertErrorsInCode(r''' -class A { - int get foo => 0; -} -mixin M on A { - static void foo() {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 61, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inConstraint_method_method() async { - await assertErrorsInCode(r''' -class A { - void foo() {} -} -mixin M on A { - static void foo() {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 57, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inConstraint_method_setter() async { - await assertErrorsInCode(r''' -class A { - set foo(_) {} -} -mixin M on A { - static void foo() {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 57, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inConstraint_setter_method() async { - await assertErrorsInCode(r''' -class A { - void foo() {} -} -mixin M on A { - static set foo(_) {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 56, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inConstraint_setter_setter() async { - await assertErrorsInCode(r''' -class A { - set foo(_) {} -} -mixin M on A { - static set foo(_) {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 56, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inInterface_getter_getter() async { - await assertErrorsInCode(r''' -class A { - int get foo => 0; -} -mixin M implements A { - static int get foo => 0; -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 72, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inInterface_getter_method() async { - await assertErrorsInCode(r''' -class A { - int get foo => 0; -} -mixin M implements A { - static void foo() {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 69, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inInterface_getter_setter() async { - await assertErrorsInCode(r''' -class A { - set foo(_) {} -} -mixin M implements A { - static int get foo => 0; -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 68, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inInterface_method_getter() async { - await assertErrorsInCode(r''' -class A { - int get foo => 0; -} -mixin M implements A { - static void foo() {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 69, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inInterface_method_method() async { - await assertErrorsInCode(r''' -class A { - void foo() {} -} -mixin M implements A { - static void foo() {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 65, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inInterface_method_setter() async { - await assertErrorsInCode(r''' -class A { - set foo(_) {} -} -mixin M implements A { - static void foo() {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 65, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inInterface_setter_method() async { - await assertErrorsInCode(r''' -class A { - void foo() {} -} -mixin M implements A { - static set foo(_) {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 64, 3), - ]); - } - - test_error_conflictingStaticAndInstance_inInterface_setter_setter() async { - await assertErrorsInCode(r''' -class A { - set foo(_) {} -} -mixin M implements A { - static set foo(_) {} -} -''', [ - error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 64, 3), - ]); - } - test_error_conflictingTypeVariableAndClass() async { await assertErrorsInCode(r''' mixin M {} diff --git a/pkg/analyzer/test/src/diagnostics/conflicting_static_and_instance_test.dart b/pkg/analyzer/test/src/diagnostics/conflicting_static_and_instance_test.dart new file mode 100644 index 000000000000..d7ac1a60347a --- /dev/null +++ b/pkg/analyzer/test/src/diagnostics/conflicting_static_and_instance_test.dart @@ -0,0 +1,753 @@ +// Copyright (c) 2019, 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. + +import 'package:analyzer/src/error/codes.dart'; +import 'package:test_reflective_loader/test_reflective_loader.dart'; + +import '../dart/resolution/driver_resolution.dart'; + +main() { + defineReflectiveSuite(() { + defineReflectiveTests(ConflictingStaticAndInstanceClassTest); + defineReflectiveTests(ConflictingStaticAndInstanceEnumTest); + defineReflectiveTests(ConflictingStaticAndInstanceMixinTest); + }); +} + +@reflectiveTest +class ConflictingStaticAndInstanceClassTest extends DriverResolutionTest { + test_inClass_getter_getter() async { + await assertErrorsInCode(r''' +class C { + static int get foo => 0; + int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 27, 3), + ]); + } + + test_inClass_getter_method() async { + await assertErrorsInCode(r''' +class C { + static int get foo => 0; + void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 27, 3), + ]); + } + + test_inClass_getter_setter() async { + await assertErrorsInCode(r''' +class C { + static int get foo => 0; + set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 27, 3), + ]); + } + + test_inClass_method_getter() async { + await assertErrorsInCode(r''' +class C { + static void foo() {} + int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 24, 3), + ]); + } + + test_inClass_method_method() async { + await assertErrorsInCode(r''' +class C { + static void foo() {} + void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 24, 3), + ]); + } + + test_inClass_method_setter() async { + await assertErrorsInCode(r''' +class C { + static void foo() {} + set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 24, 3), + ]); + } + + test_inClass_setter_getter() async { + await assertErrorsInCode(r''' +class C { + static set foo(_) {} + int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 23, 3), + ]); + } + + test_inClass_setter_method() async { + await assertErrorsInCode(r''' +class C { + static set foo(_) {} + void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 23, 3), + ]); + } + + test_inClass_setter_setter() async { + await assertErrorsInCode(r''' +class C { + static set foo(_) {} + set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 23, 3), + ]); + } + + test_inInterface_getter_getter() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +abstract class B implements A { + static int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 81, 3), + ]); + } + + test_inInterface_getter_method() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +abstract class B implements A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 78, 3), + ]); + } + + test_inInterface_getter_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +abstract class B implements A { + static int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 77, 3), + ]); + } + + test_inInterface_method_getter() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +abstract class B implements A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 78, 3), + ]); + } + + test_inInterface_method_method() async { + await assertErrorsInCode(r''' +class A { + void foo() {} +} +abstract class B implements A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 74, 3), + ]); + } + + test_inInterface_method_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +abstract class B implements A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 74, 3), + ]); + } + + test_inInterface_setter_method() async { + await assertErrorsInCode(r''' +class A { + void foo() {} +} +abstract class B implements A { + static set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 73, 3), + ]); + } + + test_inInterface_setter_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +abstract class B implements A { + static set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 73, 3), + ]); + } + + test_inMixin_getter_getter() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +class B extends Object with A { + static int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 81, 3), + ]); + } + + test_inMixin_getter_method() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +class B extends Object with A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 78, 3), + ]); + } + + test_inMixin_getter_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +class B extends Object with A { + static int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 77, 3), + ]); + } + + test_inMixin_method_getter() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +class B extends Object with A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 78, 3), + ]); + } + + test_inMixin_method_method() async { + await assertErrorsInCode(r''' +class A { + void foo() {} +} +class B extends Object with A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 74, 3), + ]); + } + + test_inMixin_method_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +class B extends Object with A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 74, 3), + ]); + } + + test_inMixin_setter_method() async { + await assertErrorsInCode(r''' +class A { + void foo() {} +} +class B extends Object with A { + static set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 73, 3), + ]); + } + + test_inMixin_setter_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +class B extends Object with A { + static set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 73, 3), + ]); + } + + test_inSuper_getter_getter() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +class B extends A { + static int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 69, 3), + ]); + } + + test_inSuper_getter_method() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +class B extends A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 66, 3), + ]); + } + + test_inSuper_getter_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +class B extends A { + static int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 65, 3), + ]); + } + + test_inSuper_method_getter() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +class B extends A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 66, 3), + ]); + } + + test_inSuper_method_method() async { + await assertErrorsInCode(r''' +class A { + void foo() {} +} +class B extends A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 62, 3), + ]); + } + + test_inSuper_method_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +class B extends A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 62, 3), + ]); + } + + test_inSuper_setter_method() async { + await assertErrorsInCode(r''' +class A { + void foo() {} +} +class B extends A { + static set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 61, 3), + ]); + } + + test_inSuper_setter_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +class B extends A { + static set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 61, 3), + ]); + } +} + +@reflectiveTest +class ConflictingStaticAndInstanceEnumTest extends DriverResolutionTest { + test_index() async { + await assertErrorsInCode(r''' +enum E { + a, index +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 14, 5), + ]); + } +} + +@reflectiveTest +class ConflictingStaticAndInstanceMixinTest extends DriverResolutionTest { + test_inConstraint_getter_getter() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +mixin M on A { + static int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 64, 3), + ]); + } + + test_inConstraint_getter_method() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +mixin M on A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 61, 3), + ]); + } + + test_inConstraint_getter_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +mixin M on A { + static int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 60, 3), + ]); + } + + test_inConstraint_method_getter() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +mixin M on A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 61, 3), + ]); + } + + test_inConstraint_method_method() async { + await assertErrorsInCode(r''' +class A { + void foo() {} +} +mixin M on A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 57, 3), + ]); + } + + test_inConstraint_method_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +mixin M on A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 57, 3), + ]); + } + + test_inConstraint_setter_method() async { + await assertErrorsInCode(r''' +class A { + void foo() {} +} +mixin M on A { + static set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 56, 3), + ]); + } + + test_inConstraint_setter_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +mixin M on A { + static set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 56, 3), + ]); + } + + test_inInterface_getter_getter() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +mixin M implements A { + static int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 72, 3), + ]); + } + + test_inInterface_getter_method() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +mixin M implements A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 69, 3), + ]); + } + + test_inInterface_getter_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +mixin M implements A { + static int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 68, 3), + ]); + } + + test_inInterface_method_getter() async { + await assertErrorsInCode(r''' +class A { + int get foo => 0; +} +mixin M implements A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 69, 3), + ]); + } + + test_inInterface_method_method() async { + await assertErrorsInCode(r''' +class A { + void foo() {} +} +mixin M implements A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 65, 3), + ]); + } + + test_inInterface_method_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +mixin M implements A { + static void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 65, 3), + ]); + } + + test_inInterface_setter_method() async { + await assertErrorsInCode(r''' +class A { + void foo() {} +} +mixin M implements A { + static set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 64, 3), + ]); + } + + test_inInterface_setter_setter() async { + await assertErrorsInCode(r''' +class A { + set foo(_) {} +} +mixin M implements A { + static set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 64, 3), + ]); + } + + test_inMixin_getter_getter() async { + await assertErrorsInCode(r''' +mixin M { + static int get foo => 0; + int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 27, 3), + ]); + } + + test_inMixin_getter_method() async { + await assertErrorsInCode(r''' +mixin M { + static int get foo => 0; + void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 27, 3), + ]); + } + + test_inMixin_getter_setter() async { + await assertErrorsInCode(r''' +mixin M { + static int get foo => 0; + set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 27, 3), + ]); + } + + test_inMixin_method_getter() async { + await assertErrorsInCode(r''' +mixin M { + static void foo() {} + int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 24, 3), + ]); + } + + test_inMixin_method_method() async { + await assertErrorsInCode(r''' +mixin M { + static void foo() {} + void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 24, 3), + ]); + } + + test_inMixin_method_setter() async { + await assertErrorsInCode(r''' +mixin M { + static void foo() {} + set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 24, 3), + ]); + } + + test_inMixin_setter_getter() async { + await assertErrorsInCode(r''' +mixin M { + static set foo(_) {} + int get foo => 0; +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 23, 3), + ]); + } + + test_inMixin_setter_method() async { + await assertErrorsInCode(r''' +mixin M { + static set foo(_) {} + void foo() {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 23, 3), + ]); + } + + test_inMixin_setter_setter() async { + await assertErrorsInCode(r''' +mixin M { + static set foo(_) {} + set foo(_) {} +} +''', [ + error(CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, 23, 3), + ]); + } +} diff --git a/pkg/analyzer/test/src/diagnostics/test_all.dart b/pkg/analyzer/test/src/diagnostics/test_all.dart index 7c96eb0d78d8..8873b0b000f7 100644 --- a/pkg/analyzer/test/src/diagnostics/test_all.dart +++ b/pkg/analyzer/test/src/diagnostics/test_all.dart @@ -25,6 +25,8 @@ import 'case_block_not_terminated_test.dart' as case_block_not_terminated; import 'cast_to_non_type_test.dart' as cast_to_non_type; import 'concrete_class_with_abstract_member_test.dart' as concrete_class_with_abstract_member; +import 'conflicting_static_and_instance_test.dart' + as conflicting_static_and_instance; import 'const_constructor_param_type_mismatch_test.dart' as const_constructor_param_type_mismatch; import 'const_constructor_with_mixin_with_field_test.dart' @@ -307,6 +309,7 @@ main() { case_block_not_terminated.main(); cast_to_non_type.main(); concrete_class_with_abstract_member.main(); + conflicting_static_and_instance.main(); const_constructor_param_type_mismatch.main(); const_constructor_with_mixin_with_field.main(); const_eval_throws_exception.main();