-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vm/compiler] Fix type of Parameter in a CatchBlockEntry
Parameter in a CatchBlockEntry may correspond to a late local variable which was not initialized yet, so its type should correctly state that it can be sentinel. TEST=vm/dart/flutter_regress_109261_test Fixes flutter/flutter#109261 Change-Id: Ia6fbbe4b9963323f84438b3f618437276e51f256 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/254440 Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
- Loading branch information
1 parent
61314e9
commit 6ad3805
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// Regression test for https://github.com/flutter/flutter/issues/109261. | ||
// Varifies that uninitialized final late local variable can be correctly | ||
// used in a catch block. | ||
|
||
import 'package:expect/expect.dart'; | ||
|
||
void testWriteToUninitialized() { | ||
late final int computationResult; | ||
|
||
try { | ||
throw 'bye'; | ||
} catch (e, s) { | ||
computationResult = 42; | ||
} | ||
|
||
Expect.equals(42, computationResult); | ||
} | ||
|
||
void testWriteToInitialized() { | ||
Expect.throws(() { | ||
late final int computationResult; | ||
|
||
try { | ||
computationResult = 10; | ||
throw 'bye'; | ||
} catch (e, s) { | ||
computationResult = 42; | ||
} | ||
}); | ||
} | ||
|
||
void testReadFromUninitialized() { | ||
Expect.throws(() { | ||
late final int computationResult; | ||
|
||
try { | ||
if (int.parse('1') == 2) { | ||
// Unreachable, just to avoid compile-time error "Late variable '...' | ||
// without initializer is definitely unassigned." | ||
computationResult = 10; | ||
} | ||
throw 'bye'; | ||
} catch (e, s) { | ||
print(computationResult); | ||
} | ||
}); | ||
} | ||
|
||
void testReadFromInitialized() { | ||
late final int computationResult; | ||
|
||
try { | ||
computationResult = 10; | ||
throw 'bye'; | ||
} catch (e, s) { | ||
Expect.equals(10, computationResult); | ||
} | ||
} | ||
|
||
main() { | ||
testWriteToUninitialized(); | ||
testWriteToInitialized(); | ||
testReadFromUninitialized(); | ||
testReadFromInitialized(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters