Skip to content

Commit 7b81625

Browse files
Anna GringauzeCommit Queue
Anna Gringauze
authored and
Commit Queue
committed
[Expression compiler] fix pattern evaluation and scope tests
- Update pattern scope tests after CFE switch improvements. - Fix incorrect end offset detection in expression compiler. Account for synthetic variables that can have offsets from later code (i.e. created for hoisting). Related: #51554 Closes: #51825 Change-Id: I07cd319f8996acae2dada96ba6e43eac9e04fbb6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290706 Reviewed-by: Nicholas Shahan <[email protected]> Commit-Queue: Anna Gringauze <[email protected]> Reviewed-by: Mark Zhou <[email protected]>
1 parent e8f6276 commit 7b81625

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

pkg/dev_compiler/lib/src/kernel/expression_compiler.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,16 @@ class FileEndOffsetCalculator extends Visitor<int?> with VisitorNullMixin<int> {
205205

206206
final int _startOffset;
207207
final TreeNode _root;
208+
final TreeNode _original;
208209

209210
int _endOffset = noOffset;
210211

211212
/// Create calculator for a scoping node with no .fileEndOffset.
212213
///
213214
/// [_root] is the parent of the scoping node.
214215
/// [_startOffset] is the start offset of the scoping node.
215-
FileEndOffsetCalculator._(this._root, this._startOffset);
216+
FileEndOffsetCalculator._(this._root, this._original)
217+
: _startOffset = _original.fileOffset;
216218

217219
/// Calculate file end offset for a scoping node.
218220
///
@@ -231,7 +233,7 @@ class FileEndOffsetCalculator extends Visitor<int?> with VisitorNullMixin<int> {
231233
/// If none found, return [noOffset].
232234
static int calculateEndOffset(TreeNode node) {
233235
for (var n = node.parent; n != null; n = n.parent) {
234-
var calculator = FileEndOffsetCalculator._(n, node.fileOffset);
236+
var calculator = FileEndOffsetCalculator._(n, node);
235237
var offset = n.accept(calculator);
236238
if (offset != noOffset) return offset!;
237239
}
@@ -240,12 +242,17 @@ class FileEndOffsetCalculator extends Visitor<int?> with VisitorNullMixin<int> {
240242

241243
@override
242244
int defaultTreeNode(TreeNode node) {
245+
if (node == _original) return _endOffset;
243246
if (node == _root) {
244247
node.visitChildren(this);
245248
if (_endOffset != noOffset) return _endOffset;
246249
return _endOffsetForNode(node);
247250
}
248-
if (_endOffset == noOffset && node.fileOffset > _startOffset) {
251+
// Skip synthesized variables as they could have offsets
252+
// from later code (in case they are hoisted, for example).
253+
if ((node is! VariableDeclaration || !node.isSynthesized) &&
254+
_endOffset == noOffset &&
255+
node.fileOffset > _startOffset) {
249256
_endOffset = node.fileOffset;
250257
}
251258
return _endOffset;

pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_amd_sound_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import 'expression_compiler_e2e_shared.dart';
1010
import 'expression_compiler_e2e_suite.dart';
1111

1212
void main() async {
13+
// Set to `true` for debug output.
14+
final debug = false;
1315
var driver = await TestDriver.init();
1416

1517
group('(Sound null safety)', () {
@@ -22,6 +24,7 @@ void main() async {
2224
soundNullSafety: true,
2325
legacyCode: false,
2426
moduleFormat: ModuleFormat.amd);
27+
setup.options.verbose = debug;
2528
runAgnosticSharedTests(setup, driver);
2629
runNullSafeSharedTests(setup, driver);
2730
});

pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_shared.dart

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -283,38 +283,20 @@ void runNullSafeSharedTests(SetupCompilerOptions setup, TestDriver driver) {
283283
expectedResult: '0');
284284
});
285285

286-
// TODO(annagrin): Remove renamed variables here and below after
287-
// const evaluator stops renaming variables used in cases.
288-
//
289-
// Issue: https://github.com/dart-lang/sdk/issues/51554
290286
test('first case scope', () async {
291-
await driver.checkScope(breakpointId: 'bp1', expectedScope: {
292-
'a': '1',
293-
'b': '2',
294-
r'a$351': r'a$351',
295-
r'b$351': r'b$351',
296-
'obj': 'obj'
297-
});
287+
await driver.checkScope(
288+
breakpointId: 'bp1',
289+
expectedScope: {'a': '1', 'b': '2', 'obj': 'obj'});
298290
});
299291

300292
test('second case scope', () async {
301-
await driver.checkScope(breakpointId: 'bp2', expectedScope: {
302-
'a': '10',
303-
'b': '10',
304-
r'a$351': '10',
305-
r'b$351': '\'20\'',
306-
'obj': 'obj'
307-
});
293+
await driver.checkScope(
294+
breakpointId: 'bp2',
295+
expectedScope: {'a': '10', 'b': '\'20\'', 'obj': 'obj'});
308296
});
309297

310298
test('default case scope', () async {
311-
await driver.checkScope(breakpointId: 'bp3', expectedScope: {
312-
'a': 'a',
313-
'b': 'b',
314-
r'a$351': r'a$351',
315-
r'b$351': r'b$351',
316-
'obj': '0'
317-
});
299+
await driver.checkScope(breakpointId: 'bp3', expectedScope: {'obj': '0'});
318300
});
319301

320302
test('result scope', () async {

0 commit comments

Comments
 (0)