Skip to content

Commit

Permalink
Version 3.7.0-323.0.dev
Browse files Browse the repository at this point in the history
Merge 8063ed1 into dev
  • Loading branch information
Dart CI committed Jan 13, 2025
2 parents 1482910 + 8063ed1 commit f6ed8d7
Show file tree
Hide file tree
Showing 91 changed files with 545 additions and 902 deletions.
131 changes: 1 addition & 130 deletions pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1897,44 +1897,6 @@ class Parser {
}
}

/// Check if [token] is the usage of 'required' in a formal parameter in a
/// context where it's not legal (i.e. in non-nnbd-mode).
bool _isUseOfRequiredInNonNNBD(Token token) {
if (token.next is StringToken && token.next!.value() == "required") {
// Possible recovery: Figure out if we're in a situation like
// required covariant? <type> name
// (in non-nnbd-mode) where the required modifier is not legal and thus
// would normally be parsed as the type.
token = token.next!;
Token next = token.next!;
// Skip modifiers.
while (next.isModifier) {
token = next;
next = next.next!;
}
// Parse the (potential) new type.
TypeInfo typeInfoAlternative = computeType(
token,
/* required = */ false,
/* inDeclaration = */ true,
);
token = typeInfoAlternative.skipType(token);
next = token.next!;

// We've essentially ignored the 'required' at this point.
// `token` is (in the good state) the last token of the type,
// `next` is (in the good state) the name;
// Are we in a 'good' state?
if (typeInfoAlternative != noType &&
next.isIdentifier &&
(next.next!.isA(TokenType.COMMA) ||
next.next!.isA(TokenType.CLOSE_CURLY_BRACKET))) {
return true;
}
}
return false;
}

/// ```
/// normalFormalParameter:
/// functionFormalParameter |
Expand All @@ -1959,13 +1921,6 @@ class Parser {
token = parseMetadataStar(token);

Token? skippedNonRequiredRequired;
if (_isUseOfRequiredInNonNNBD(token)) {
skippedNonRequiredRequired = token.next!;
reportRecoverableErrorWithToken(skippedNonRequiredRequired,
codes.templateUnexpectedModifierInNonNnbd);
token = token.next!;
}

Token next = token.next!;
Token start = next;

Expand Down Expand Up @@ -3419,58 +3374,13 @@ class Parser {
return parseTopLevelMemberImpl(token).next!;
}

/// Check if [token] is the usage of 'late' before a field declaration in a
/// context where it's not legal (i.e. in non-nnbd-mode).
bool _isUseOfLateInNonNNBD(Token token) {
if (token is StringToken && token.value() == "late") {
// Possible recovery: Figure out if we're in a situation like
// late final? <type>/var/const name [...]
// (in non-nnbd-mode) where the late modifier is not legal and thus would
// normally be parsed as the type.
Token next = token.next!;
// Skip modifiers.
while (next.isModifier) {
token = next;
next = next.next!;
}
// Parse the (potential) new type.
TypeInfo typeInfoAlternative = computeType(
token,
/* required = */ false,
/* inDeclaration = */ true,
);
token = typeInfoAlternative.skipType(token);
next = token.next!;

// We've essentially ignored the 'late' at this point.
// `token` is (in the good state) the last token of the type,
// `next` is (in the good state) the name;
// Are we in a 'good' state?
if (typeInfoAlternative != noType &&
next.isIdentifier &&
indicatesMethodOrField(next.next!)) {
return true;
}
}
return false;
}

Token parseTopLevelMemberImpl(Token token) {
Token beforeStart = token;
Token next = token.next!;
listener.beginTopLevelMember(next);

Token? skippedNonLateLate;

if (_isUseOfLateInNonNNBD(next)) {
skippedNonLateLate = next;
reportRecoverableErrorWithToken(
skippedNonLateLate, codes.templateUnexpectedModifierInNonNnbd);
token = token.next!;
beforeStart = token;
next = token.next!;
}

Token? externalToken;
Token? augmentToken;
Token? lateToken;
Expand Down Expand Up @@ -3787,20 +3697,7 @@ class Parser {
if (semicolon.isA(TokenType.SEMICOLON)) {
token = semicolon;
} else {
// Recovery
if (kind == DeclarationKind.TopLevel &&
beforeType.next!.isIdentifier &&
beforeType.next!.lexeme == 'extension') {
// Looks like an extension method
// TODO(danrubel): Remove when extension methods are enabled by default
// because then 'extension' will be interpreted as a built-in
// and this code will never be executed
reportExperimentNotEnabled(ExperimentalFlag.extensionMethods,
beforeType.next!, beforeType.next!);
token = rewriter.insertSyntheticToken(token, TokenType.SEMICOLON);
} else {
token = ensureSemicolon(token);
}
token = ensureSemicolon(token);
}
switch (kind) {
case DeclarationKind.TopLevel:
Expand Down Expand Up @@ -4520,14 +4417,6 @@ class Parser {

Token? skippedNonLateLate;

if (_isUseOfLateInNonNNBD(token.next!)) {
skippedNonLateLate = token.next!;
reportRecoverableErrorWithToken(
skippedNonLateLate, codes.templateUnexpectedModifierInNonNnbd);
token = token.next!;
beforeStart = token;
}

Token? covariantToken;
Token? abstractToken;
Token? augmentToken;
Expand Down Expand Up @@ -8162,24 +8051,6 @@ class Parser {
Token parseExpressionStatementOrDeclarationAfterModifiers(Token beforeType,
Token start, Token? lateToken, Token? varFinalOrConst, TypeInfo? typeInfo,
[ForPartsContext? forPartsContext]) {
// In simple cases check for bad 'late' modifier in non-nnbd-mode.
if (typeInfo == null &&
lateToken == null &&
varFinalOrConst == null &&
beforeType == start &&
_isUseOfLateInNonNNBD(beforeType.next!)) {
lateToken = beforeType.next!;
reportRecoverableErrorWithToken(
lateToken, codes.templateUnexpectedModifierInNonNnbd);
beforeType = start = beforeType.next!;

// The below doesn't parse modifiers, so we need to do it here.
ModifierContext context = new ModifierContext(this);
beforeType =
start = context.parseVariableDeclarationModifiers(beforeType);
varFinalOrConst = context.varFinalOrConst;
}

if (allowPatterns &&
varFinalOrConst != null &&
(varFinalOrConst.isA(Keyword.VAR) ||
Expand Down
43 changes: 4 additions & 39 deletions pkg/_fe_analyzer_shared/lib/src/scanner/abstract_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ abstract class AbstractScanner implements Scanner {
/// based upon the specified language version.
final LanguageVersionChanged? languageVersionChanged;

/// Experimental flag for enabling scanning of the `extension` token.
bool _enableExtensionMethods = false;

/// Experimental flag for enabling scanning of NNBD tokens
/// such as 'required' and 'late'.
bool _enableNonNullable = false;

/// Experimental flag for enabling scanning of `>>>`.
/// See https://github.com/dart-lang/language/issues/61
/// and https://github.com/dart-lang/language/issues/60
Expand Down Expand Up @@ -165,8 +158,6 @@ abstract class AbstractScanner implements Scanner {
allowLazyStrings = true {
this.tail = this.tokens;
this.errorTail = this.tokens;
this._enableExtensionMethods = copyFrom._enableExtensionMethods;
this._enableNonNullable = copyFrom._enableNonNullable;
this._enableTripleShift = copyFrom._enableTripleShift;
this.tokenStart = copyFrom.tokenStart;
this.groupingStack = copyFrom.groupingStack;
Expand All @@ -175,8 +166,6 @@ abstract class AbstractScanner implements Scanner {
@override
set configuration(ScannerConfiguration? config) {
if (config != null) {
_enableExtensionMethods = config.enableExtensionMethods;
_enableNonNullable = config.enableNonNullable;
_enableTripleShift = config.enableTripleShift;
_forAugmentationLibrary = config.forAugmentationLibrary;
}
Expand Down Expand Up @@ -1053,11 +1042,9 @@ abstract class AbstractScanner implements Scanner {
$EQ, TokenType.QUESTION_QUESTION_EQ, TokenType.QUESTION_QUESTION);
} else if (next == $PERIOD) {
next = advance();
if (_enableNonNullable) {
if ($PERIOD == next) {
appendPrecedenceToken(TokenType.QUESTION_PERIOD_PERIOD);
return advance();
}
if ($PERIOD == next) {
appendPrecedenceToken(TokenType.QUESTION_PERIOD_PERIOD);
return advance();
}
appendPrecedenceToken(TokenType.QUESTION_PERIOD);
return next;
Expand Down Expand Up @@ -1577,10 +1564,6 @@ abstract class AbstractScanner implements Scanner {
if (languageVersionChanged != null) {
// TODO(danrubel): make this required and remove the languageVersion field
languageVersionChanged!(this, languageVersion);
} else {
// TODO(danrubel): remove this hack and require listener to update
// the scanner's configuration.
configuration = ScannerConfiguration.classic;
}
if (includeComments) {
_appendToCommentStream(languageVersion);
Expand Down Expand Up @@ -1745,13 +1728,6 @@ abstract class AbstractScanner implements Scanner {
if (keyword == null) {
return tokenizeIdentifier(next, start, allowDollar);
}
if (!_enableExtensionMethods && keyword == Keyword.EXTENSION) {
return tokenizeIdentifier(next, start, allowDollar);
}
if (!_enableNonNullable &&
(keyword == Keyword.LATE || keyword == Keyword.REQUIRED)) {
return tokenizeIdentifier(next, start, allowDollar);
}
if (!_forAugmentationLibrary && keyword == Keyword.AUGMENT) {
return tokenizeIdentifier(next, start, allowDollar);
}
Expand Down Expand Up @@ -2168,16 +2144,7 @@ class LineStarts extends Object with ListMixin<int> {
/// [ScannerConfiguration] contains information for configuring which tokens
/// the scanner produces based upon the Dart language level.
class ScannerConfiguration {
static const ScannerConfiguration classic = const ScannerConfiguration();
static const ScannerConfiguration nonNullable =
const ScannerConfiguration(enableNonNullable: true);

/// Experimental flag for enabling scanning of the `extension` keyword.
final bool enableExtensionMethods;

/// Experimental flag for enabling scanning of NNBD tokens
/// such as 'required' and 'late'
final bool enableNonNullable;
static const ScannerConfiguration nonNullable = const ScannerConfiguration();

/// Experimental flag for enabling scanning of `>>>`.
/// See https://github.com/dart-lang/language/issues/61
Expand All @@ -2188,8 +2155,6 @@ class ScannerConfiguration {
final bool forAugmentationLibrary;

const ScannerConfiguration({
this.enableExtensionMethods = false,
this.enableNonNullable = false,
this.enableTripleShift = false,
this.forAugmentationLibrary = false,
});
Expand Down
2 changes: 0 additions & 2 deletions pkg/_fe_analyzer_shared/test/macros/code_optimizer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,6 @@ void assertEdits({
code,
libraryDeclarationNames: libraryDeclarationNames,
scannerConfiguration: ScannerConfiguration(
enableExtensionMethods: true,
enableNonNullable: true,
forAugmentationLibrary: true,
),
throwIfHasErrors: throwIfHasErrors,
Expand Down
6 changes: 0 additions & 6 deletions pkg/_fe_analyzer_shared/test/scanner_benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ void main(List<String> args) {
hasErrors = scanString(
content,
configuration: new ScannerConfiguration(
enableExtensionMethods: true,
enableNonNullable: true,
enableTripleShift: true,
),
includeComments: true,
Expand All @@ -66,8 +64,6 @@ void main(List<String> args) {
hasErrors = scan(
contentBytes,
configuration: new ScannerConfiguration(
enableExtensionMethods: true,
enableNonNullable: true,
enableTripleShift: true,
),
includeComments: true,
Expand All @@ -80,8 +76,6 @@ void main(List<String> args) {
hasErrors = scan(
tmp,
configuration: new ScannerConfiguration(
enableExtensionMethods: true,
enableNonNullable: true,
enableTripleShift: true,
),
includeComments: true,
Expand Down
3 changes: 0 additions & 3 deletions pkg/analyzer/lib/src/dart/scanner/scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ class Scanner {
featureSet == null
? fasta.ScannerConfiguration()
: fasta.ScannerConfiguration(
enableExtensionMethods:
featureSet.isEnabled(Feature.extension_methods),
enableTripleShift: featureSet.isEnabled(Feature.triple_shift),
enableNonNullable: featureSet.isEnabled(Feature.non_nullable),
forAugmentationLibrary: featureSet.isEnabled(Feature.macros),
);
}
12 changes: 0 additions & 12 deletions pkg/analyzer/test/generated/extension_methods_parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:analyzer/src/dart/scanner/scanner.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import '../util/feature_sets.dart';
import 'parser_test_base.dart';

main() {
Expand Down Expand Up @@ -219,17 +218,6 @@ class C {}
expect(extension.members, hasLength(0));
}

void test_simple_not_enabled() {
parseCompilationUnit(
'extension E on C { }',
errors: [
expectedError(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 0, 9),
expectedError(ParserErrorCode.MISSING_FUNCTION_PARAMETERS, 15, 1)
],
featureSet: FeatureSets.language_2_3,
);
}

void test_simple_with() {
var unit = parseCompilationUnit('extension E with C { }', errors: [
expectedError(ParserErrorCode.EXPECTED_INSTEAD, 12, 4),
Expand Down
5 changes: 1 addition & 4 deletions pkg/analyzer/test/generated/parser_test_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,7 @@ class FastaParserTestCase
var languageVersion = LibraryLanguageVersion(
package: ExperimentStatus.currentVersion, override: null);
var result = scanString(content,
configuration: featureSet.isEnabled(Feature.non_nullable)
? ScannerConfiguration.nonNullable
: ScannerConfiguration.classic,
includeComments: true,
configuration: ScannerConfiguration.nonNullable, includeComments: true,
languageVersionChanged: (scanner, overrideVersion) {
languageVersion = LibraryLanguageVersion(
package: ExperimentStatus.currentVersion,
Expand Down
5 changes: 0 additions & 5 deletions pkg/analyzer/test/util/feature_sets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import 'package:analyzer_utilities/test/experiments/experiments.dart';
import 'package:pub_semver/pub_semver.dart';

class FeatureSets {
static final FeatureSet language_2_3 = FeatureSet.fromEnableFlags2(
sdkLanguageVersion: Version.parse('2.3.0'),
flags: [],
);

static final FeatureSet language_2_9 = FeatureSet.fromEnableFlags2(
sdkLanguageVersion: Version.parse('2.9.0'),
flags: [],
Expand Down
2 changes: 0 additions & 2 deletions pkg/front_end/lib/src/base/incremental_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1232,8 +1232,6 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
return null;
}
ScannerConfiguration scannerConfiguration = new ScannerConfiguration(
enableExtensionMethods: true /* can't be disabled */,
enableNonNullable: true /* can't be disabled */,
enableTripleShift:
/* should this be on the library? */
/* this is effectively what the constant evaluator does */
Expand Down
5 changes: 1 addition & 4 deletions pkg/front_end/lib/src/kernel/macro/macro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1355,10 +1355,7 @@ class MacroApplications {

ScannerResult scannerResult = scan(sourceUtf8,
configuration: new ScannerConfiguration(
enableExtensionMethods: true,
enableNonNullable: true,
enableTripleShift: true,
forAugmentationLibrary: true));
enableTripleShift: true, forAugmentationLibrary: true));
_sourceLoader.target.addSourceInformation(augmentationImportUri,
augmentationFileUri, scannerResult.lineStarts, sourceUtf8);
for (Uri intermediateAugmentationUri in intermediateAugmentationUris) {
Expand Down
Loading

0 comments on commit f6ed8d7

Please sign in to comment.