analyzer: Consider "Immutable" annotations the same as "immutable"
Fixes https://github.com/dart-lang/sdk/issues/57670 Change-Id: I5a9ecd153c4e4de21e00860a7743f946096b0849 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503680 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
61a266f8dc
commit
433b4fa3c8
@@ -1564,6 +1564,10 @@ class ElementAnnotationImpl
|
||||
/// factory.
|
||||
static const String _factoryVariableName = 'factory';
|
||||
|
||||
/// The name of the class used to mark a class and its subclasses as being
|
||||
/// immutable.
|
||||
static const String _immutableClassName = 'Immutable';
|
||||
|
||||
/// The name of the top-level variable used to mark a class and its subclasses
|
||||
/// as being immutable.
|
||||
static const String _immutableVariableName = 'immutable';
|
||||
@@ -1793,7 +1797,9 @@ class ElementAnnotationImpl
|
||||
bool get isFactory => _isPackageMetaGetter(_factoryVariableName);
|
||||
|
||||
@override
|
||||
bool get isImmutable => _isPackageMetaGetter(_immutableVariableName);
|
||||
bool get isImmutable =>
|
||||
_isPackageMetaGetter(_immutableVariableName) ||
|
||||
_isPackageMetaConstructor(_immutableClassName);
|
||||
|
||||
@override
|
||||
bool get isInternal => _isPackageMetaGetter(_internalVariableName);
|
||||
@@ -1949,6 +1955,10 @@ class ElementAnnotationImpl
|
||||
return _isTopGetter(libraryName: 'dart.core', name: name);
|
||||
}
|
||||
|
||||
bool _isPackageMetaConstructor(String className) {
|
||||
return _isConstructor(libraryName: _metaLibName, className: className);
|
||||
}
|
||||
|
||||
bool _isPackageMetaGetter(String name) {
|
||||
return _isTopGetter(libraryName: _metaLibName, name: name);
|
||||
}
|
||||
|
||||
@@ -490,6 +490,19 @@ class C {
|
||||
);
|
||||
}
|
||||
|
||||
test_immutableInstantiation_nonConstConstructor() async {
|
||||
await assertDiagnostics(
|
||||
r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@Immutable('')
|
||||
class A {
|
||||
A();
|
||||
}
|
||||
''',
|
||||
[lint(60, 1)],
|
||||
);
|
||||
}
|
||||
|
||||
test_implementsImmutable() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@@ -108,6 +108,20 @@ var x = C([]);
|
||||
);
|
||||
}
|
||||
|
||||
test_listLiteral_noConst_instantiationAnnotation() async {
|
||||
await assertDiagnostics(
|
||||
r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@Immutable('')
|
||||
class C {
|
||||
const C(List<Object> p);
|
||||
}
|
||||
var x = C([]);
|
||||
''',
|
||||
[lint(97, 2)],
|
||||
);
|
||||
}
|
||||
|
||||
test_listLiteral_notConstable_noConst() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
Reference in New Issue
Block a user