-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report EXTENSION_CONFLICTING_STATIC_AND_INSTANCE and DUPLICATE_DEFINI…
…TION for extensions. [email protected] Change-Id: I237ee3edc6a2196693638c12c59d1530a1f15152 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112605 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
- Loading branch information
1 parent
a244295
commit 9713ce1
Showing
7 changed files
with
381 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
pkg/analyzer/test/src/diagnostics/duplicate_definition_extension_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// 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/dart/analysis/features.dart'; | ||
import 'package:analyzer/src/error/codes.dart'; | ||
import 'package:analyzer/src/generated/engine.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../dart/resolution/driver_resolution.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(DuplicateDefinitionExtensionTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class DuplicateDefinitionExtensionTest extends DriverResolutionTest { | ||
@override | ||
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl() | ||
..contextFeatures = new FeatureSet.forTesting( | ||
sdkVersion: '2.3.0', additionalFeatures: [Feature.extension_methods]); | ||
|
||
CompileTimeErrorCode get _errorCode => | ||
CompileTimeErrorCode.DUPLICATE_DEFINITION; | ||
|
||
test_extendedType_instance() async { | ||
await assertNoErrorsInCode(''' | ||
class A { | ||
int get foo => 0; | ||
set foo(_) {} | ||
void bar() {} | ||
} | ||
extension E on A { | ||
int get foo => 0; | ||
set foo(_) {} | ||
void bar() {} | ||
} | ||
'''); | ||
} | ||
|
||
test_extendedType_static() async { | ||
await assertNoErrorsInCode(''' | ||
class A { | ||
static int get foo => 0; | ||
static set foo(_) {} | ||
static void bar() {} | ||
} | ||
extension E on A { | ||
static int get foo => 0; | ||
static set foo(_) {} | ||
static void bar() {} | ||
} | ||
'''); | ||
} | ||
|
||
test_instance_getter_getter() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
int get foo => 0; | ||
int get foo => 0; | ||
} | ||
''', [ | ||
error(_errorCode, 54, 3), | ||
]); | ||
} | ||
|
||
test_instance_getter_setter() async { | ||
await assertNoErrorsInCode(''' | ||
extension E on String { | ||
int get foo => 0; | ||
set foo(_) {} | ||
} | ||
'''); | ||
} | ||
|
||
test_instance_method_method() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
void foo() {} | ||
void foo() {} | ||
} | ||
''', [ | ||
error(_errorCode, 47, 3), | ||
]); | ||
} | ||
|
||
test_instance_setter_setter() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
set foo(_) {} | ||
set foo(_) {} | ||
} | ||
''', [ | ||
error(_errorCode, 46, 3), | ||
]); | ||
} | ||
|
||
test_static_getter_getter() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static int get foo => 0; | ||
static int get foo => 0; | ||
} | ||
''', [ | ||
error(_errorCode, 68, 3), | ||
]); | ||
} | ||
|
||
test_static_getter_setter() async { | ||
await assertNoErrorsInCode(''' | ||
extension E on String { | ||
static int get foo => 0; | ||
static set foo(_) {} | ||
} | ||
'''); | ||
} | ||
|
||
test_static_method_method() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static void foo() {} | ||
static void foo() {} | ||
} | ||
''', [ | ||
error(_errorCode, 61, 3), | ||
]); | ||
} | ||
|
||
test_static_setter_setter() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static set foo(_) {} | ||
static set foo(_) {} | ||
} | ||
''', [ | ||
error(_errorCode, 60, 3), | ||
]); | ||
} | ||
} |
168 changes: 168 additions & 0 deletions
168
pkg/analyzer/test/src/diagnostics/extension_conflicting_static_and_instance_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// 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/dart/analysis/features.dart'; | ||
import 'package:analyzer/src/error/codes.dart'; | ||
import 'package:analyzer/src/generated/engine.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../dart/resolution/driver_resolution.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(ExtensionConflictingStaticAndInstanceTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class ExtensionConflictingStaticAndInstanceTest extends DriverResolutionTest { | ||
@override | ||
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl() | ||
..contextFeatures = new FeatureSet.forTesting( | ||
sdkVersion: '2.3.0', additionalFeatures: [Feature.extension_methods]); | ||
|
||
CompileTimeErrorCode get _errorCode => | ||
CompileTimeErrorCode.EXTENSION_CONFLICTING_STATIC_AND_INSTANCE; | ||
|
||
test_extendedType_getter() async { | ||
await assertNoErrorsInCode(''' | ||
class A { | ||
static int get foo => 0; | ||
int get bar => 0; | ||
} | ||
extension E on A { | ||
int get foo => 0; | ||
static int get bar => 0; | ||
} | ||
'''); | ||
} | ||
|
||
test_extendedType_method() async { | ||
await assertNoErrorsInCode(''' | ||
class A { | ||
static void foo() {} | ||
void bar() {} | ||
} | ||
extension E on A { | ||
void foo() {} | ||
static void bar() {} | ||
} | ||
'''); | ||
} | ||
|
||
test_extendedType_setter() async { | ||
await assertNoErrorsInCode(''' | ||
class A { | ||
static set foo(_) {} | ||
set bar(_) {} | ||
} | ||
extension E on A { | ||
set foo(_) {} | ||
static set bar(_) {} | ||
} | ||
'''); | ||
} | ||
|
||
test_getter_getter() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static int get foo => 0; | ||
int get foo => 0; | ||
} | ||
''', [ | ||
error(_errorCode, 41, 3), | ||
]); | ||
} | ||
|
||
test_getter_method() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static int get foo => 0; | ||
void foo() {} | ||
} | ||
''', [ | ||
error(_errorCode, 41, 3), | ||
]); | ||
} | ||
|
||
test_getter_setter() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static int get foo => 0; | ||
set foo(_) {} | ||
} | ||
''', [ | ||
error(_errorCode, 41, 3), | ||
]); | ||
} | ||
|
||
test_method_getter() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static void foo() {} | ||
int get foo => 0; | ||
} | ||
''', [ | ||
error(_errorCode, 38, 3), | ||
]); | ||
} | ||
|
||
test_method_method() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static void foo() {} | ||
void foo() {} | ||
} | ||
''', [ | ||
error(_errorCode, 38, 3), | ||
]); | ||
} | ||
|
||
test_method_setter() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static void foo() {} | ||
set foo(_) {} | ||
} | ||
''', [ | ||
error(_errorCode, 38, 3), | ||
]); | ||
} | ||
|
||
test_setter_getter() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static set foo(_) {} | ||
int get foo => 0; | ||
} | ||
''', [ | ||
error(_errorCode, 37, 3), | ||
]); | ||
} | ||
|
||
test_setter_method() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static set foo(_) {} | ||
void foo() {} | ||
} | ||
''', [ | ||
error(_errorCode, 37, 3), | ||
]); | ||
} | ||
|
||
test_setter_setter() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static set foo(_) {} | ||
set foo(_) {} | ||
} | ||
''', [ | ||
error(_errorCode, 37, 3), | ||
]); | ||
} | ||
} |
Oops, something went wrong.