-
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.
Add a diagnostic when an extension override is used to access a stati…
…c member. Also added missing awaits to several previously committed tests. Change-Id: Ide2d714b02e36f097f7c958b609dd780ff333253 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109420 Reviewed-by: Phil Quitslund <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
- Loading branch information
1 parent
c304336
commit 227ff83
Showing
14 changed files
with
160 additions
and
59 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
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
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
81 changes: 81 additions & 0 deletions
81
pkg/analyzer/test/src/diagnostics/extension_override_access_to_static_member_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,81 @@ | ||
// 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(ExtensionOverrideAccessToStaticMemberTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class ExtensionOverrideAccessToStaticMemberTest extends DriverResolutionTest { | ||
@override | ||
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl() | ||
..contextFeatures = new FeatureSet.forTesting( | ||
sdkVersion: '2.3.0', additionalFeatures: [Feature.extension_methods]); | ||
|
||
test_getter() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static String get empty => ''; | ||
} | ||
void f() { | ||
E('a').empty; | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.EXTENSION_OVERRIDE_ACCESS_TO_STATIC_MEMBER, 79, | ||
5), | ||
]); | ||
} | ||
|
||
test_getterAndSetter() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static String get empty => ''; | ||
static void set empty(String s) {} | ||
} | ||
void f() { | ||
E('a').empty += 'b'; | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.EXTENSION_OVERRIDE_ACCESS_TO_STATIC_MEMBER, | ||
116, 5), | ||
]); | ||
} | ||
|
||
test_method() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static String empty() => ''; | ||
} | ||
void f() { | ||
E('a').empty(); | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.EXTENSION_OVERRIDE_ACCESS_TO_STATIC_MEMBER, 77, | ||
5), | ||
]); | ||
} | ||
|
||
test_setter() async { | ||
await assertErrorsInCode(''' | ||
extension E on String { | ||
static void set empty(String s) {} | ||
} | ||
void f() { | ||
E('a').empty = 'b'; | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.EXTENSION_OVERRIDE_ACCESS_TO_STATIC_MEMBER, 83, | ||
5), | ||
]); | ||
} | ||
} |
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
Oops, something went wrong.