mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 20:09:41 +00:00
linter: Fix issue with extension type methods as possibly const arguments
Fixes https://github.com/dart-lang/linter/issues/4978 Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try Change-Id: I532f491355bc34028b19d323102f038dff861445 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371780 Auto-Submit: Sam Rawlins <srawlins@google.com> Commit-Queue: Sam Rawlins <srawlins@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com> Commit-Queue: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
parent
7ec9514093
commit
3c65563735
|
@ -341,6 +341,7 @@ class _ConstantAnalysisErrorListener extends AnalysisErrorListener {
|
|||
case CompileTimeErrorCode
|
||||
.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST:
|
||||
case CompileTimeErrorCode.CONST_EVAL_EXTENSION_METHOD:
|
||||
case CompileTimeErrorCode.CONST_EVAL_EXTENSION_TYPE_METHOD:
|
||||
case CompileTimeErrorCode.CONST_EVAL_METHOD_INVOCATION:
|
||||
case CompileTimeErrorCode.CONST_EVAL_PROPERTY_ACCESS:
|
||||
case CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL:
|
||||
|
|
|
@ -3176,6 +3176,21 @@ void Function(int, {int? b})
|
|||
''');
|
||||
}
|
||||
|
||||
test_visitUnaryExpression_extensionType() async {
|
||||
await assertErrorsInCode('''
|
||||
extension type const A(int it) {
|
||||
int operator -() => 0;
|
||||
}
|
||||
|
||||
const v1 = A(1);
|
||||
const v2 = -v1;
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_EXTENSION_TYPE_METHOD, 89, 3),
|
||||
]);
|
||||
var result = _topLevelVar('v2');
|
||||
_assertNull(result);
|
||||
}
|
||||
|
||||
void _assertHasPrimitiveEqualityFalse(String name) {
|
||||
var value = _evaluateConstant(name);
|
||||
var featureSet = result.libraryElement.featureSet;
|
||||
|
|
|
@ -180,6 +180,23 @@ A f(int i) => A('adjacent' '$i');
|
|||
''');
|
||||
}
|
||||
|
||||
test_cannotBeConst_argumentIsExtensionTypeMethodCall() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
final class A {
|
||||
final Ex f;
|
||||
const A(this.f);
|
||||
|
||||
void foo() {
|
||||
var a = A(-f);
|
||||
}
|
||||
}
|
||||
|
||||
extension type const Ex(int i) implements int {
|
||||
Ex operator -() => Ex(-i);
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_cannotBeConst_argumentIsListLiteral_nonLiteralElement() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
class A {
|
||||
|
|
Loading…
Reference in a new issue