File tree 4 files changed +33
-4
lines changed
4 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -8,9 +8,11 @@ import 'package:analyzer/dart/element/element.dart';
8
8
import 'package:analyzer/dart/element/type.dart' ;
9
9
import 'package:analyzer/file_system/physical_file_system.dart' ;
10
10
import 'package:analyzer/src/dart/ast/ast.dart' ; // ignore: implementation_imports
11
+ import 'package:analyzer/src/dart/element/element.dart' ; // ignore: implementation_imports
11
12
import 'package:analyzer/src/dart/element/member.dart' ; // ignore: implementation_imports
12
- // ignore: implementation_imports
13
- import 'package:analyzer/src/dart/element/type.dart' show InvalidTypeImpl;
13
+ import 'package:analyzer/src/dart/element/type.dart' // ignore: implementation_imports
14
+ show
15
+ InvalidTypeImpl;
14
16
import 'package:collection/collection.dart' ;
15
17
16
18
import 'analyzer.dart' ;
@@ -337,6 +339,11 @@ extension ElementExtension on Element {
337
339
}
338
340
return self;
339
341
}
342
+
343
+ bool get isMacro {
344
+ var self = this ;
345
+ return self is ClassElementImpl && self.isMacro;
346
+ }
340
347
}
341
348
342
349
extension ExpressionExtension on Expression ? {
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import 'package:analyzer/src/lint/linter.dart'; // ignore: implementation_import
9
9
import 'package:collection/collection.dart' show IterableExtension;
10
10
11
11
import '../analyzer.dart' ;
12
+ import '../extensions.dart' ;
12
13
13
14
const _desc = r'Prefer declaring `const` constructors on `@immutable` classes.' ;
14
15
@@ -74,8 +75,10 @@ class _Visitor extends SimpleAstVisitor<void> {
74
75
if (element == null ) return ;
75
76
if (element.isConst) return ;
76
77
if (node.body is ! EmptyFunctionBody ) return ;
77
- if (element.enclosingElement.mixins.isNotEmpty) return ;
78
- if (! _hasImmutableAnnotation (element.enclosingElement)) return ;
78
+ var enclosingElement = element.enclosingElement;
79
+ if (enclosingElement.isMacro) return ;
80
+ if (enclosingElement.mixins.isNotEmpty) return ;
81
+ if (! _hasImmutableAnnotation (enclosingElement)) return ;
79
82
var isRedirected =
80
83
element.isFactory && element.redirectedConstructor != null ;
81
84
if (isRedirected && (element.redirectedConstructor? .isConst ?? false )) {
Original file line number Diff line number Diff line change @@ -764,6 +764,12 @@ abstract class _ContextResolutionTest with ResourceProviderMixin {
764
764
);
765
765
}
766
766
767
+ @mustCallSuper
768
+ Future <void > tearDown () async {
769
+ await _analysisContextCollection? .dispose ();
770
+ _analysisContextCollection = null ;
771
+ }
772
+
767
773
DriverBasedAnalysisContext _contextFor (String path) {
768
774
_createAnalysisContexts ();
769
775
Original file line number Diff line number Diff line change @@ -392,6 +392,19 @@ class B extends A {
392
392
]);
393
393
}
394
394
395
+ test_macroConstructor () async {
396
+ await assertDiagnostics (r'''
397
+ import 'package:meta/meta.dart';
398
+
399
+ @immutable
400
+ macro class M {
401
+ M();
402
+ }
403
+ ''' , [
404
+ // TODO(pq): add non-const constructor compilation error when implemented
405
+ ]);
406
+ }
407
+
395
408
test_returnOfInvalidType () async {
396
409
await assertDiagnostics (r'''
397
410
import 'package:meta/meta.dart';
You can’t perform that action at this time.
0 commit comments