mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
Report ILLEGAL_LANGUAGE_VERSION_OVERRIDE even when the package language version causes it.
Change-Id: I617d67ba06758e3f57d9ff0048a080d0a699fc96 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232126 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
5b1a22f4fc
commit
7282a40c49
|
@ -2745,21 +2745,26 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
|||
return;
|
||||
}
|
||||
|
||||
var languageVersionToken = node.languageVersionToken;
|
||||
if (languageVersionToken == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var languageVersion = _currentLibrary.languageVersion.effective;
|
||||
if (sourceLanguageConstraint.allows(languageVersion)) {
|
||||
return;
|
||||
}
|
||||
|
||||
errorReporter.reportErrorForToken(
|
||||
CompileTimeErrorCode.ILLEGAL_LANGUAGE_VERSION_OVERRIDE,
|
||||
languageVersionToken,
|
||||
['$sourceLanguageConstraint'],
|
||||
);
|
||||
var languageVersionToken = node.languageVersionToken;
|
||||
if (languageVersionToken != null) {
|
||||
errorReporter.reportErrorForToken(
|
||||
CompileTimeErrorCode.ILLEGAL_LANGUAGE_VERSION_OVERRIDE,
|
||||
languageVersionToken,
|
||||
['$sourceLanguageConstraint'],
|
||||
);
|
||||
} else {
|
||||
errorReporter.reportErrorForOffset(
|
||||
CompileTimeErrorCode.ILLEGAL_LANGUAGE_VERSION_OVERRIDE,
|
||||
0,
|
||||
0,
|
||||
['$sourceLanguageConstraint'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify that the given implements [clause] does not implement classes such
|
||||
|
|
|
@ -40,6 +40,31 @@ int a = null;
|
|||
]);
|
||||
}
|
||||
|
||||
test_hasPackageLanguage_less_hasOverride_greater() async {
|
||||
writeTestPackageConfig(
|
||||
PackageConfigFileBuilder(),
|
||||
languageVersion: '2.9',
|
||||
);
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.12
|
||||
void f() {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_hasPackageLanguage_less_noOverride_less() async {
|
||||
writeTestPackageConfig(
|
||||
PackageConfigFileBuilder(),
|
||||
languageVersion: '2.9',
|
||||
);
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
void f() {}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.ILLEGAL_LANGUAGE_VERSION_OVERRIDE, 0, 0),
|
||||
]);
|
||||
}
|
||||
|
||||
test_noOverride() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
void f() {}
|
||||
|
|
Loading…
Reference in a new issue