Skip to content

Commit

Permalink
Version 3.6.0-44.0.dev
Browse files Browse the repository at this point in the history
Merge 01b1156 into dev
  • Loading branch information
Dart CI committed Jul 16, 2024
2 parents b608d37 + 01b1156 commit 18e673c
Show file tree
Hide file tree
Showing 77 changed files with 954 additions and 252 deletions.
20 changes: 10 additions & 10 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ vars = {
"bazel_worker_rev": "02f190b88df771fc8e05c07d4b64ae942c02f456",
"benchmark_harness_rev": "a06785cdfc51538e3556c1d59bb4f03426e9e1c5",
"boolean_selector_rev": "c5468f44fd9ca0ea3435e1a0a84ff9b6fac38261",
"browser_launcher_rev": "60126904a26b761d29b4f2d76292ff3c089160de",
"browser_launcher_rev": "fe7ffa13ba59ec6f7d56256f79059344555fdaf2",
"characters_rev": "7633a16a22c626e19ca750223237396315268a06",
"cli_util_rev": "64192706344d0598784bebe1abc4a9bfc2608de0",
"clock_rev": "ad428ea8b75fa0d7ba629791552d40478745c54a",
"cli_util_rev": "6a0bb9292ea4bb2c9e547af03da4c9948f9556a1",
"clock_rev": "6e43768a0b135a0d36fc886907b70c4bf27117e6",
"collection_rev": "0c1f829c29da1d63488be774f430b2035a565d6f",
"convert_rev": "9035cafefc1da4315f26058734d0c2a19d5ab56a",
"crypto_rev": "1216790ba704a0ab194f9cd0da2d65e1767f3342",
Expand All @@ -143,15 +143,15 @@ vars = {
# and land the review.
#
# For more details, see https://github.com/dart-lang/sdk/issues/30164.
"dart_style_rev": "cedd052cf1f2683019469b10966ffc6af114bac4", # disable tools/rev_sdk_deps.dart
"dartdoc_rev": "5e8de164057dd5f7f34eee0ad443dc2f59c60c1c",
"ecosystem_rev": "4171189c0dd0f5e02426fcded7d1fa2d09be6133",
"dart_style_rev": "a6ad7693555a9add6f98ad6fd94de80d35c89415", # disable tools/rev_sdk_deps.dart
"dartdoc_rev": "f6f93ddf172716ae2a92f5e986ecbefaf9dd8a06",
"ecosystem_rev": "2635536f8fbb13ca8349e5e461a1b45320bc01ea",
"file_rev": "855831c242a17c2dee163828d52710d9043c7c8d",
"fixnum_rev": "6c19e60366ce3d5edfaed51a7c12c98e7977977e",
"flute_rev": "a531c96a8b43d015c6bfbbfe3ab54867b0763b8b",
"glob_rev": "8b05be87f84f74d90dc0c15956f3ff95805322e5",
"html_rev": "0da420ca1e196cda54ede476d0d8d3ecf55375ef",
"http_rev": "4178b67e7970ff02926e79649db5ab473b46cf30",
"http_rev": "edbb5a9711570afa46e2ae9fca8cf8366f672715",
"http_multi_server_rev": "8348be1bf8fd17881e2643086e68c9d2b28dd9ce",
"http_parser_rev": "ce528cf82f3d26ac761e29b2494a9e0c270d4939",
"intl_rev": "5d65e3808ce40e6282e40881492607df4e35669f",
Expand All @@ -176,17 +176,17 @@ vars = {
"source_maps_rev": "5f82c613664ade03c7a6d0e6c59687c69dec894b",
"source_span_rev": "f81cd4a2df630a97264fb4015fb93944b5b98b11",
"sse_rev": "52d042ff9ab2d0e5bc26805d74a03077a67861e1",
"stack_trace_rev": "4fd3e2a2dc6611febf4cfb9197ebf9e60fc6a34d",
"stack_trace_rev": "090d3d186c085fdb913fe5350c666f8d0bd0f60f",
"stream_channel_rev": "28a65331aa2d66a5e953205aa462bcdb1e240a5b",
"string_scanner_rev": "a40bbbd83f1176bcc0021b336f5841310f91d8cb",
"sync_http_rev": "ab8377eba79baff3d77e8c75d502efc2b85a9342",
"tar_rev": "552a49d7595e444184d4f91e9afd533aa253a31d",
"term_glyph_rev": "38a158f55006cf30942c928171ea601ee5e0308f",
"test_rev": "14f9b3ec7e06f987dd70bb1f47267462ce218048",
"test_rev": "2c2ac49de0e9d6ea9744c6e7990d5730806410c0",
"test_descriptor_rev": "90743bc16bc00526a1b9a64f813614be9b2479d9",
"test_process_rev": "6223572ca16d7585d5f08d9281de6a5734e45150",
"test_reflective_loader_rev": "6e648863b39aab8d0204e769d25805eea9db0ac4",
"tools_rev": "43a8582a85d2220b5f1ca8383d97587792085b36",
"tools_rev": "6a07a1625f57c4b5844e26e51d30de0444a84763",
"typed_data_rev": "365468a74251c930a463daf5b8f13227e269111a",
"vector_math_rev": "2cfbe2c115a57b368ccbc3c89ebd38a06764d3d1",
"watcher_rev": "0484625589d8512b36a7ad898a6cc6351d24c556",
Expand Down
85 changes: 54 additions & 31 deletions pkg/_fe_analyzer_shared/lib/src/parser/directive_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ import '../scanner/token.dart';
import 'parser_impl.dart';

class DirectiveContext {
/// Whether the `enhanced-parts` feature is enabled.
final bool enableFeatureEnhancedParts;

DirectiveState state = DirectiveState.Unknown;

DirectiveContext({
required this.enableFeatureEnhancedParts,
});

void checkScriptTag(Parser parser, Token token) {
if (state == DirectiveState.Unknown) {
state = DirectiveState.Script;
Expand All @@ -26,32 +33,42 @@ class DirectiveContext {
}

void checkExport(Parser parser, Token token) {
if (state.index <= DirectiveState.ImportAndExport.index) {
state = DirectiveState.ImportAndExport;
return;
}
// Recovery
if (state == DirectiveState.Part) {
parser.reportRecoverableError(token, messageExportAfterPart);
} else if (state == DirectiveState.PartOf) {
parser.reportRecoverableError(token, messageNonPartOfDirectiveInPart);
} else {
parser.reportRecoverableError(token, messageDirectiveAfterDeclaration);
switch (state) {
case DirectiveState.Unknown:
case DirectiveState.Script:
case DirectiveState.Library:
case DirectiveState.ImportAndExport:
state = DirectiveState.ImportAndExport;
case DirectiveState.Part:
parser.reportRecoverableError(token, messageExportAfterPart);
case DirectiveState.PartOf:
if (enableFeatureEnhancedParts) {
state = DirectiveState.ImportAndExport;
} else {
parser.reportRecoverableError(token, messageNonPartOfDirectiveInPart);
}
case DirectiveState.Declarations:
parser.reportRecoverableError(token, messageDirectiveAfterDeclaration);
}
}

void checkImport(Parser parser, Token token) {
if (state.index <= DirectiveState.ImportAndExport.index) {
state = DirectiveState.ImportAndExport;
return;
}
// Recovery
if (state == DirectiveState.Part) {
parser.reportRecoverableError(token, messageImportAfterPart);
} else if (state == DirectiveState.PartOf) {
parser.reportRecoverableError(token, messageNonPartOfDirectiveInPart);
} else {
parser.reportRecoverableError(token, messageDirectiveAfterDeclaration);
switch (state) {
case DirectiveState.Unknown:
case DirectiveState.Script:
case DirectiveState.Library:
case DirectiveState.ImportAndExport:
state = DirectiveState.ImportAndExport;
case DirectiveState.Part:
parser.reportRecoverableError(token, messageImportAfterPart);
case DirectiveState.PartOf:
if (enableFeatureEnhancedParts) {
state = DirectiveState.ImportAndExport;
} else {
parser.reportRecoverableError(token, messageNonPartOfDirectiveInPart);
}
case DirectiveState.Declarations:
parser.reportRecoverableError(token, messageDirectiveAfterDeclaration);
}
}

Expand All @@ -71,15 +88,21 @@ class DirectiveContext {
}

void checkPart(Parser parser, Token token) {
if (state.index <= DirectiveState.Part.index) {
state = DirectiveState.Part;
return;
}
// Recovery
if (state == DirectiveState.PartOf) {
parser.reportRecoverableError(token, messageNonPartOfDirectiveInPart);
} else {
parser.reportRecoverableError(token, messageDirectiveAfterDeclaration);
switch (state) {
case DirectiveState.Unknown:
case DirectiveState.Script:
case DirectiveState.Library:
case DirectiveState.ImportAndExport:
case DirectiveState.Part:
state = DirectiveState.Part;
case DirectiveState.PartOf:
if (enableFeatureEnhancedParts) {
state = DirectiveState.ImportAndExport;
} else {
parser.reportRecoverableError(token, messageNonPartOfDirectiveInPart);
}
case DirectiveState.Declarations:
parser.reportRecoverableError(token, messageDirectiveAfterDeclaration);
}
}

Expand Down
15 changes: 12 additions & 3 deletions pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,14 @@ class Parser {
/// [parsePrimaryPattern] and [parsePattern].
bool isLastPatternAllowedInsideUnaryPattern = false;

/// Whether the `enhanced-parts` feature is enabled.
final bool enableFeatureEnhancedParts;

Parser(
this.listener, {
this.useImplicitCreationExpression = true,
this.allowPatterns = false,
this.enableFeatureEnhancedParts = false,
}) : assert(listener != null); // ignore:unnecessary_null_comparison

/// Executes [callback]; however if `this` is the `TestParser` (from
Expand Down Expand Up @@ -401,7 +405,9 @@ class Parser {

listener.beginCompilationUnit(token);
int count = 0;
DirectiveContext directiveState = new DirectiveContext();
DirectiveContext directiveState = new DirectiveContext(
enableFeatureEnhancedParts: enableFeatureEnhancedParts,
);
token = syntheticPreviousToken(token);
if (identical(token.next!.type, TokenType.SCRIPT_TAG)) {
directiveState.checkScriptTag(this, token.next!);
Expand Down Expand Up @@ -448,7 +454,9 @@ class Parser {
Token parseDirectives(Token token) {
listener.beginCompilationUnit(token);
int count = 0;
DirectiveContext directiveState = new DirectiveContext();
DirectiveContext directiveState = new DirectiveContext(
enableFeatureEnhancedParts: enableFeatureEnhancedParts,
);
token = syntheticPreviousToken(token);
while (!token.next!.isEof) {
final Token start = token.next!;
Expand Down Expand Up @@ -1227,13 +1235,14 @@ class Parser {

/// ```
/// partDirective:
/// 'part' uri ';'
/// 'part' uri ('if' '(' test ')' uri)* ';'
/// ;
/// ```
Token parsePart(Token partKeyword) {
assert(optional('part', partKeyword));
listener.beginPart(partKeyword);
Token token = ensureLiteralString(partKeyword);
token = parseConditionalUriStar(token);
token = ensureSemicolon(token);
listener.endPart(partKeyword, token);
return token;
Expand Down
2 changes: 1 addition & 1 deletion pkg/_fe_analyzer_shared/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: _fe_analyzer_shared
version: 72.0.0
version: 73.0.0
description: Logic that is shared between the front_end and analyzer packages.
repository: https://github.com/dart-lang/sdk/tree/main/pkg/_fe_analyzer_shared

Expand Down
4 changes: 2 additions & 2 deletions pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ import 'package:analysis_server/src/server/performance.dart';
import 'package:analysis_server/src/services/user_prompts/dart_fix_prompt_manager.dart';
import 'package:analysis_server/src/utilities/extensions/flutter.dart';
import 'package:analysis_server/src/utilities/process.dart';
import 'package:analyzer/dart/analysis/context_locator.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/exception/exception.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/instrumentation/instrumentation.dart';
import 'package:analyzer/src/dart/analysis/context_locator.dart';
import 'package:analyzer/src/dart/analysis/status.dart' as analysis;
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
Expand Down Expand Up @@ -984,7 +984,7 @@ class LspAnalysisServer extends AnalysisServer {
/// This is used when there are no workspace folders open directly.
List<String> _getRootsForOpenFiles() {
var openFiles = priorityFiles.toList();
var contextLocator = ContextLocator(resourceProvider: resourceProvider);
var contextLocator = ContextLocatorImpl(resourceProvider: resourceProvider);
var roots = contextLocator.locateRoots(includedPaths: openFiles);

var packages = <String>{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,25 @@ class ConvertToIntLiteral extends ResolvedCorrectionProducer {
try {
intValue = literal.value.truncate();
} catch (e) {
// Double cannot be converted to int
// A double that cannot be converted to an int.
return;
}

if (intValue == null || intValue != literal.value) {
if (intValue != literal.value) {
return;
}

await builder.addDartFileEdit(file, (builder) {
if (!literal.literal.lexeme.contains('e')) {
var indexOfDecimal = literal.literal.lexeme.indexOf('.');
if (indexOfDecimal > 0) {
// Preserve digit separators by just truncating the existing lexeme.
builder.addDeletion(SourceRange(literal.offset + indexOfDecimal,
literal.length - indexOfDecimal));
return;
}
}

builder.addReplacement(SourceRange(literal.offset, literal.length),
(builder) {
builder.write('$intValue');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ const double myDouble = 42;
''');
}

Future<void> test_decimal_negative() async {
await resolveTestCode('''
const double myDouble = -/*caret*/42.0;
''');
await assertHasAssist('''
const double myDouble = -42;
''');
}

Future<void> test_decimal_noAssistWithLint() async {
createAnalysisOptionsFile(lints: [LintNames.prefer_int_literals]);
verifyNoTestUnitErrors = false;
Expand All @@ -38,6 +47,24 @@ const double myDouble = /*caret*/42.0;
await assertNoAssist();
}

Future<void> test_decimal_noDigitsLeftOfDecimal() async {
await resolveTestCode('''
const double myDouble = /*caret*/.0;
''');
await assertHasAssist('''
const double myDouble = 0;
''');
}

Future<void> test_decimalWithSeparators() async {
await resolveTestCode('''
const double myDouble = /*caret*/4_200.000_000;
''');
await assertHasAssist('''
const double myDouble = 4_200;
''');
}

Future<void> test_notDouble() async {
await resolveTestCode('''
const double myDouble = /*caret*/42;
Expand All @@ -47,10 +74,19 @@ const double myDouble = /*caret*/42;

Future<void> test_scientific() async {
await resolveTestCode('''
const double myDouble = /*caret*/4.2e1;
const double myDouble = /*caret*/4.2e3;
''');
await assertHasAssist('''
const double myDouble = 42;
const double myDouble = 4200;
''');
}

Future<void> test_scientificWithSeparators() async {
await resolveTestCode('''
const double myDouble = /*caret*/4_00.200_000e3;
''');
await assertHasAssist('''
const double myDouble = 400200;
''');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class _ChildrenFinder extends SimpleAstVisitor<void> {

@override
void visitPartDirective(PartDirective node) {
_fromList(node.metadata);
_fromList(node.metadata) || _fromList(node.configurations);
}

@override
Expand Down
4 changes: 3 additions & 1 deletion pkg/analyzer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 6.8.0-dev
## 6.8.0
* Add `AnalysisContextCollection.dispose()`. It must be invoked at the end.
* Deprecated `ContextLocator` and `ContextBuilder`.
Use `AnalysisContextCollection` instead.

## 6.7.0
* Deprecated `File.createSource()`, it violates levels of abstraction.
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/doc/process/new_language_feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The features are listed roughly in dependency order.
- [ ] Constant evaluation
- [ ] Index and search
- [ ] Warnings (annotation-based, unused\*, strict-mode-based, a few others)
- [ ] `InheritanceOverrideVerifier` (report errors and warnings related to overrides)
- [ ] `OverrideVerifier` and `InheritanceOverrideVerifier` (report errors and warnings related to overrides)
- [ ] `ErrorVerifier` (report other errors and warnings)
- [ ] `FfiVerifier` (report errors and warnings related to FFI)
- [ ] Unused elements warnings
Expand Down
1 change: 1 addition & 0 deletions pkg/analyzer/lib/dart/analysis/context_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:analyzer/src/dart/analysis/context_builder.dart';
/// A utility class used to build an analysis context based on a context root.
///
/// Clients may not extend, implement or mix-in this class.
@Deprecated('Use AnalysisContextCollection instead')
abstract class ContextBuilder {
/// Initialize a newly created context builder. If a [resourceProvider] is
/// given, then it will be used to access the file system, otherwise the
Expand Down
1 change: 1 addition & 0 deletions pkg/analyzer/lib/dart/analysis/context_locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:analyzer/src/dart/analysis/context_locator.dart';
/// folders and a list of excluded files and folders.
///
/// Clients may not extend, implement or mix-in this class.
@Deprecated('Use AnalysisContextCollection instead')
abstract class ContextLocator {
/// Initialize a newly created context locator. If a [resourceProvider] is
/// supplied, it will be used to access the file system. Otherwise the default
Expand Down
Loading

0 comments on commit 18e673c

Please sign in to comment.