mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 21:01:20 +00:00
Issue 46758. LATE_FINAL_FIELD_WITH_CONST_CONSTRUCTOR.
Does not pass https://dart-review.googlesource.com/c/sdk/+/211140 yet, because requires one more fix, not reporting CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD for const redirect constructors. Bug: https://github.com/dart-lang/sdk/issues/46985 Bug: https://github.com/dart-lang/sdk/issues/46758 Change-Id: If6289b595545216d2d4e247214c5176a6a9d4a31 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209222 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
8d5c80ce83
commit
965af148f3
|
@ -7542,8 +7542,10 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
|
|||
// }
|
||||
// ```
|
||||
static const CompileTimeErrorCode LATE_FINAL_FIELD_WITH_CONST_CONSTRUCTOR =
|
||||
CompileTimeErrorCode('LATE_FINAL_FIELD_WITH_CONST_CONSTRUCTOR',
|
||||
"Can't have a late final field in a class with a const constructor.",
|
||||
CompileTimeErrorCode(
|
||||
'LATE_FINAL_FIELD_WITH_CONST_CONSTRUCTOR',
|
||||
"Can't have a late final field in a class with a generative "
|
||||
"const constructor.",
|
||||
correction: "Try removing the 'late' modifier, or don't declare "
|
||||
"'const' constructors.",
|
||||
hasPublishedDocs: true);
|
||||
|
|
|
@ -2817,8 +2817,10 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
|||
// The field is in an extension and should be handled elsewhere.
|
||||
return;
|
||||
}
|
||||
var hasConstConstructor = enclosingClass.constructors.any((c) => c.isConst);
|
||||
if (!hasConstConstructor) return;
|
||||
|
||||
var hasGenerativeConstConstructor =
|
||||
_enclosingClass!.constructors.any((c) => c.isConst && !c.isFactory);
|
||||
if (!hasGenerativeConstConstructor) return;
|
||||
|
||||
errorReporter.reportErrorForToken(
|
||||
CompileTimeErrorCode.LATE_FINAL_FIELD_WITH_CONST_CONSTRUCTOR,
|
||||
|
|
|
@ -62,6 +62,22 @@ class A {
|
|||
''');
|
||||
}
|
||||
|
||||
test_class_hasConstFactoryConstructor() async {
|
||||
await assertNoErrorsInCode('''
|
||||
class Base {
|
||||
Base();
|
||||
const factory Base.empty() = _Empty;
|
||||
late final int property;
|
||||
}
|
||||
|
||||
class _Empty implements Base {
|
||||
const _Empty();
|
||||
int get property => 0;
|
||||
set property(_) {}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_noConstConstructor() async {
|
||||
await assertNoErrorsInCode('''
|
||||
class A {
|
||||
|
|
|
@ -7438,7 +7438,7 @@ void f() {
|
|||
|
||||
### late_final_field_with_const_constructor
|
||||
|
||||
_Can't have a late final field in a class with a const constructor._
|
||||
_Can't have a late final field in a class with a generative const constructor._
|
||||
|
||||
#### Description
|
||||
|
||||
|
|
Loading…
Reference in a new issue