Skip to content

Commit 8af83f0

Browse files
author
Dart CI
committed
Version 3.9.0-230.0.dev
Merge d194fce into dev
2 parents e43244f + d194fce commit 8af83f0

26 files changed

+484
-87
lines changed

pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_test.dart

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,7 +2377,10 @@ main() {
23772377
x.as_('int'),
23782378
checkPromoted(x, 'int'),
23792379
checkPromoted(y, 'int'),
2380-
]).catch_(body: [checkNotPromoted(x), checkPromoted(y, 'int')]),
2380+
]).catch_(
2381+
type: 'dynamic',
2382+
body: [checkNotPromoted(x), checkPromoted(y, 'int')],
2383+
),
23812384
]);
23822385
});
23832386

@@ -2396,6 +2399,7 @@ main() {
23962399
checkPromoted(x, 'int'),
23972400
getSsaNodes((nodes) => ssaAfterTry = nodes[x]!),
23982401
]).catch_(
2402+
type: 'dynamic',
23992403
body: [
24002404
checkNotPromoted(x),
24012405
getSsaNodes((nodes) => expect(nodes[x], isNot(ssaAfterTry))),
@@ -2418,7 +2422,7 @@ main() {
24182422
try_([
24192423
localFunction([x.write(expr('int?'))]),
24202424
return_(),
2421-
]).catch_(body: [x.as_('int'), checkNotPromoted(x)]),
2425+
]).catch_(type: 'dynamic', body: [x.as_('int'), checkNotPromoted(x)]),
24222426
]);
24232427
});
24242428

@@ -2429,8 +2433,11 @@ main() {
24292433
h.run([
24302434
declare(x, type: 'int?', initializer: expr('int?')),
24312435
try_([])
2432-
.catch_(body: [x.as_('int'), checkPromoted(x, 'int')])
2433-
.catch_(body: [checkNotPromoted(x)]),
2436+
.catch_(
2437+
type: 'dynamic',
2438+
body: [x.as_('int'), checkPromoted(x, 'int')],
2439+
)
2440+
.catch_(type: 'dynamic', body: [checkNotPromoted(x)]),
24342441
]);
24352442
},
24362443
);
@@ -2447,6 +2454,54 @@ main() {
24472454
]);
24482455
});
24492456

2457+
test('Exception variable is promotable', () {
2458+
var e = Var('e');
2459+
h.run([
2460+
try_([]).catch_(
2461+
exception: e,
2462+
body: [checkNotPromoted(e), e.as_('int'), checkPromoted(e, 'int')],
2463+
),
2464+
]);
2465+
});
2466+
2467+
test('Exception variable is promotable', () {
2468+
var e = Var('e');
2469+
h.run([
2470+
try_([]).catch_(
2471+
type: 'Object',
2472+
exception: e,
2473+
body: [
2474+
e.checkType('Object'),
2475+
checkNotPromoted(e),
2476+
e.as_('String'),
2477+
checkPromoted(e, 'String'),
2478+
],
2479+
),
2480+
]);
2481+
});
2482+
2483+
test('StackTrace variable is promotable', () {
2484+
TypeRegistry.addInterfaceTypeName('StackTraceSubtype');
2485+
h.addSuperInterfaces(
2486+
'StackTraceSubtype',
2487+
(_) => [Type('StackTrace'), Type('Object')],
2488+
);
2489+
var e = Var('e');
2490+
var st = Var('st');
2491+
h.run([
2492+
try_([]).catch_(
2493+
exception: e,
2494+
stackTrace: st,
2495+
body: [
2496+
st.checkType('StackTrace'),
2497+
checkNotPromoted(st),
2498+
st.as_('StackTraceSubtype'),
2499+
checkPromoted(st, 'StackTraceSubtype'),
2500+
],
2501+
),
2502+
]);
2503+
});
2504+
24502505
test(
24512506
'tryCatchStatement_catchEnd() joins catch state with after-try state',
24522507
() {
@@ -2460,7 +2515,7 @@ main() {
24602515
try_([
24612516
x.as_('int'),
24622517
y.as_('int'),
2463-
]).catch_(body: [x.as_('int'), z.as_('int')]),
2518+
]).catch_(type: 'dynamic', body: [x.as_('int'), z.as_('int')]),
24642519
// Only x should be promoted, because it's the only variable
24652520
// promoted in both the try body and the catch handler.
24662521
checkPromoted(x, 'int'), checkNotPromoted(y), checkNotPromoted(z),
@@ -2477,8 +2532,8 @@ main() {
24772532
declare(y, type: 'int?', initializer: expr('int?')),
24782533
declare(z, type: 'int?', initializer: expr('int?')),
24792534
try_([return_()])
2480-
.catch_(body: [x.as_('int'), y.as_('int')])
2481-
.catch_(body: [x.as_('int'), z.as_('int')]),
2535+
.catch_(type: 'dynamic', body: [x.as_('int'), y.as_('int')])
2536+
.catch_(type: 'dynamic', body: [x.as_('int'), z.as_('int')]),
24822537
// Only x should be promoted, because it's the only variable promoted
24832538
// in both catch handlers.
24842539
checkPromoted(x, 'int'), checkNotPromoted(y), checkNotPromoted(z),

pkg/_fe_analyzer_shared/test/mini_ast.dart

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,25 +1008,51 @@ class CastPattern extends Pattern {
10081008
/// [TryBuilder.catch_] to create instances of this class.
10091009
class CatchClause {
10101010
final Statement body;
1011+
final Type? exceptionType;
10111012
final Var? exception;
10121013
final Var? stackTrace;
10131014

1014-
CatchClause._(this.body, this.exception, this.stackTrace);
1015+
CatchClause._(
1016+
this.body,
1017+
this.exceptionType,
1018+
this.exception,
1019+
this.stackTrace,
1020+
) {
1021+
if (exception == null && stackTrace != null) {
1022+
fail(
1023+
'If a stack trace variable is provided, an exception variable must be '
1024+
'provided too',
1025+
);
1026+
}
1027+
if (exception == null && exceptionType == null) {
1028+
fail(
1029+
'If no exception variable is provided, an exception type must be '
1030+
'provided',
1031+
);
1032+
}
1033+
}
10151034

10161035
@override
10171036
String toString() {
1018-
String initialPart;
1019-
if (stackTrace != null) {
1020-
initialPart = 'catch (${exception!.name}, ${stackTrace!.name})';
1021-
} else if (exception != null) {
1022-
initialPart = 'catch (${exception!.name})';
1023-
} else {
1024-
initialPart = 'on ...';
1025-
}
1026-
return '$initialPart $body';
1037+
return [
1038+
if (exceptionType case var exceptionType?) 'on $exceptionType',
1039+
if (exception case Var(name: var exceptionName))
1040+
switch (stackTrace) {
1041+
Var(name: var stackTraceName) =>
1042+
'catch ($exceptionName, $stackTraceName)',
1043+
_ => 'catch ($exceptionName)',
1044+
},
1045+
body,
1046+
].join(' ');
10271047
}
10281048

10291049
void _preVisit(PreVisitor visitor) {
1050+
if (exception case var exception?) {
1051+
visitor._assignedVariables.declare(exception);
1052+
}
1053+
if (stackTrace case var stackTrace?) {
1054+
visitor._assignedVariables.declare(stackTrace);
1055+
}
10301056
body.preVisit(visitor);
10311057
}
10321058
}
@@ -5374,6 +5400,7 @@ class Throw extends Expression {
53745400

53755401
abstract class TryBuilder {
53765402
TryStatement catch_({
5403+
String? type,
53775404
Var? exception,
53785405
Var? stackTrace,
53795406
required List<ProtoStatement> body,
@@ -5400,6 +5427,7 @@ class TryStatementImpl extends TryStatement {
54005427

54015428
@override
54025429
TryStatement catch_({
5430+
String? type,
54035431
Var? exception,
54045432
Var? stackTrace,
54055433
required List<ProtoStatement> body,
@@ -5411,6 +5439,7 @@ class TryStatementImpl extends TryStatement {
54115439
...catches,
54125440
CatchClause._(
54135441
Block._(body, location: computeLocation()),
5442+
type == null ? null : Type(type),
54145443
exception,
54155444
stackTrace,
54165445
),
@@ -6749,6 +6778,8 @@ class _MiniAstTypeAnalyzer
67496778
if (catchClauses.isNotEmpty) {
67506779
flow.tryCatchStatement_bodyEnd(body);
67516780
for (var catch_ in catchClauses) {
6781+
catch_.exception?._type = catch_.exceptionType ?? Type('dynamic');
6782+
catch_.stackTrace?._type = Type('StackTrace');
67526783
flow.tryCatchStatement_catchBegin(catch_.exception, catch_.stackTrace);
67536784
dispatchStatement(catch_.body);
67546785
flow.tryCatchStatement_catchEnd();

pkg/_fe_analyzer_shared/test/mini_types.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,7 @@ abstract final class TypeRegistry {
11751175
addInterfaceTypeName('Object');
11761176
_add(stream);
11771177
addInterfaceTypeName('String');
1178+
addInterfaceTypeName('StackTrace');
11781179
_add(void_);
11791180
}
11801181

@@ -1224,6 +1225,7 @@ class TypeSystem {
12241225
'Map': (_) => [Type('Object')],
12251226
'Object': (_) => [],
12261227
'num': (_) => [Type('Object')],
1228+
'StackTrace': (_) => [Type('Object')],
12271229
'String': (_) => [Type('Object')],
12281230
};
12291231

pkg/analysis_server_plugin/lib/src/correction/ignore_diagnostic.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ abstract class _BaseIgnoreDiagnostic extends ResolvedCorrectionProducer {
247247
/// - `error.code` is already ignored in the `errors` list.
248248
bool get _isCodeUnignorable {
249249
var cannotIgnore = (analysisOptions as AnalysisOptionsImpl)
250-
.unignorableNames
250+
.unignorableDiagnosticCodeNames
251251
.contains(diagnostic.diagnosticCode.name);
252252

253253
if (cannotIgnore) {

pkg/analyzer/lib/src/dart/analysis/analysis_options.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ final class AnalysisOptionsBuilder {
5959

6060
FormatterOptions formatterOptions = FormatterOptions();
6161

62-
Set<String> unignorableNames = {};
62+
Set<String> unignorableDiagnosticCodeNames = {};
6363

6464
List<PluginConfiguration> pluginConfigurations = [];
6565

@@ -81,7 +81,7 @@ final class AnalysisOptionsBuilder {
8181
chromeOsManifestChecks: chromeOsManifestChecks,
8282
codeStyleOptions: codeStyleOptions,
8383
formatterOptions: formatterOptions,
84-
unignorableNames: unignorableNames,
84+
unignorableDiagnosticCodeNames: unignorableDiagnosticCodeNames,
8585
);
8686
}
8787

@@ -315,17 +315,19 @@ final class AnalysisOptionsBuilder {
315315
);
316316
if (processors.isNotEmpty &&
317317
processors.first.severity?.displayName == severity) {
318-
unignorableNames.add(e.name);
318+
unignorableDiagnosticCodeNames.add(e.name);
319319
continue;
320320
}
321321
// Otherwise, add [error] if its default severity is [severity].
322322
if (e.severity.displayName == severity) {
323-
unignorableNames.add(e.name);
323+
unignorableDiagnosticCodeNames.add(e.name);
324324
}
325325
}
326326
}
327327
}
328-
unignorableNames.addAll(stringValues.map((name) => name.toUpperCase()));
328+
unignorableDiagnosticCodeNames.addAll(
329+
stringValues.map((name) => name.toUpperCase()),
330+
);
329331
}
330332
}
331333

@@ -402,10 +404,9 @@ class AnalysisOptionsImpl implements AnalysisOptions {
402404
@override
403405
final FormatterOptions formatterOptions;
404406

405-
/// The set of "un-ignorable" error names, as parsed from an analysis options
406-
/// file.
407-
// TODO(srawlins): Rename to `unignorableCodes`. 'Names' is ambiguous.
408-
final Set<String> unignorableNames;
407+
/// The set of "un-ignorable" diagnostic names, as parsed from an analysis
408+
/// options file.
409+
final Set<String> unignorableDiagnosticCodeNames;
409410

410411
/// Returns a newly instantiated [AnalysisOptionsImpl].
411412
///
@@ -514,7 +515,7 @@ class AnalysisOptionsImpl implements AnalysisOptions {
514515
required this.chromeOsManifestChecks,
515516
required this.codeStyleOptions,
516517
required this.formatterOptions,
517-
required this.unignorableNames,
518+
required this.unignorableDiagnosticCodeNames,
518519
}) : _contextFeatures = contextFeatures {
519520
(codeStyleOptions as CodeStyleOptionsImpl).options = this;
520521
}

pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ class LibraryAnalyzer {
374374
fileAnalysis.diagnosticListener.diagnostics,
375375
fileAnalysis.ignoreInfo,
376376
fileAnalysis.unit.lineInfo,
377-
_analysisOptions.unignorableNames,
377+
_analysisOptions.unignorableDiagnosticCodeNames,
378378
validateUnnecessaryIgnores,
379379
).reportErrors();
380380
}
@@ -573,7 +573,7 @@ class LibraryAnalyzer {
573573
return diagnostics;
574574
}
575575

576-
var unignorableCodes = _analysisOptions.unignorableNames;
576+
var unignorableCodes = _analysisOptions.unignorableDiagnosticCodeNames;
577577

578578
bool isIgnored(Diagnostic diagnostic) {
579579
var code = diagnostic.diagnosticCode;

pkg/analyzer/test/src/options/analysis_options_test.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ analyzer:
5353
- another
5454
''');
5555

56-
var unignorableNames = analysisOptions.unignorableNames;
57-
expect(unignorableNames, unorderedEquals(['ONE_ERROR_CODE', 'ANOTHER']));
56+
var unignorableCodeNames = analysisOptions.unignorableDiagnosticCodeNames;
57+
expect(
58+
unignorableCodeNames,
59+
unorderedEquals(['ONE_ERROR_CODE', 'ANOTHER']),
60+
);
5861
}
5962

6063
test_analyzer_cannotIgnore_severity() {
@@ -64,9 +67,9 @@ analyzer:
6467
- error
6568
''');
6669

67-
var unignorableNames = analysisOptions.unignorableNames;
68-
expect(unignorableNames, contains('INVALID_ANNOTATION'));
69-
expect(unignorableNames.length, greaterThan(500));
70+
var unignorableCodeNames = analysisOptions.unignorableDiagnosticCodeNames;
71+
expect(unignorableCodeNames, contains('INVALID_ANNOTATION'));
72+
expect(unignorableCodeNames.length, greaterThan(500));
7073
}
7174

7275
test_analyzer_cannotIgnore_severity_withProcessor() {
@@ -78,8 +81,8 @@ analyzer:
7881
- error
7982
''');
8083

81-
var unignorableNames = analysisOptions.unignorableNames;
82-
expect(unignorableNames, contains('UNUSED_IMPORT'));
84+
var unignorableCodeNames = analysisOptions.unignorableDiagnosticCodeNames;
85+
expect(unignorableCodeNames, contains('UNUSED_IMPORT'));
8386
}
8487

8588
test_analyzer_chromeos_checks() {

runtime/platform/utils_macos.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,15 @@ int32_t DarwinVersionInternal() {
141141
int32_t minor_version = 0;
142142

143143
#if defined(DART_HOST_OS_IOS)
144-
// We do not expect to run on version of iOS <12.0 so we can assume that
145-
// kernel version is off by 6 from iOS version (e.g. kernel 18.0 is iOS 12.0).
146-
// This only holds starting from iOS 4.0.
147-
major_version = kernel_major_version - 6;
144+
if (kernel_major_version >= 25) {
145+
// Starting from iOS 26 kernel versions are 1 behind OS version.
146+
major_version = kernel_major_version + 1;
147+
} else {
148+
// We do not expect to run on version of iOS <12.0 so we can assume that
149+
// kernel version is off by 6 from iOS version (e.g. kernel 18.0 is
150+
// iOS 12.0). This only holds starting from iOS 4.0.
151+
major_version = kernel_major_version - 6;
152+
}
148153
if (major_version >= 15) {
149154
// After iOS 15 minor version of kernel is the same as minor version of
150155
// the iOS release. Before iOS 15 these numbers were not in sync. However

runtime/platform/utils_macos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ int32_t DarwinVersion();
3131
}
3232

3333
DEFINE_IS_OS_FUNCS(18_4, 180400)
34+
DEFINE_IS_OS_FUNCS(26_0, 260000)
3435

3536
#else
3637

0 commit comments

Comments
 (0)