-
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.
- Loading branch information
Showing
13 changed files
with
293 additions
and
115 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// 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/110715. | ||
// Verifies that compiler doesn't elide null check for a parameter in | ||
// a catch block in async/async* methods. | ||
|
||
import 'dart:async'; | ||
import 'package:vm/testing/il_matchers.dart'; | ||
|
||
@pragma('vm:never-inline') | ||
@pragma('vm:testing:print-flow-graph') | ||
Stream<Object> bug1(void Function()? f, void Function() g) async* { | ||
try { | ||
g(); | ||
throw 'error'; | ||
} catch (e) { | ||
// Should not crash when 'f' is null. | ||
f?.call(); | ||
} | ||
} | ||
|
||
@pragma('vm:never-inline') | ||
@pragma('vm:testing:print-flow-graph') | ||
Future<Object> bug2(void Function()? f, void Function() g) async { | ||
try { | ||
g(); | ||
throw 'error'; | ||
} catch (e) { | ||
// Should not crash when 'f' is null. | ||
f?.call(); | ||
} | ||
return ''; | ||
} | ||
|
||
void main() async { | ||
print(await bug1(null, () {}).toList()); | ||
print(await bug1(() {}, () {}).toList()); | ||
print(await bug2(null, () {})); | ||
print(await bug2(() {}, () {})); | ||
} | ||
|
||
void matchIL$bug1(FlowGraph graph) { | ||
graph.dump(); | ||
graph.match([ | ||
match.block('Graph'), | ||
match.block('Function'), | ||
match.block('Join'), | ||
match.block('CatchBlock', [ | ||
'v0' << match.Parameter(), | ||
match.Branch(match.StrictCompare('v0', match.any, kind: '==='), | ||
ifTrue: 'B6', ifFalse: 'B7'), | ||
]), | ||
'B6' << | ||
match.block('Target', [ | ||
match.Goto('B4'), | ||
]), | ||
'B7' << | ||
match.block('Target', [ | ||
match.ClosureCall(), | ||
match.Goto('B4'), | ||
]), | ||
'B4' << | ||
match.block('Join', [ | ||
match.Return(), | ||
]), | ||
]); | ||
} | ||
|
||
void matchIL$bug2(FlowGraph graph) { | ||
graph.dump(); | ||
graph.match([ | ||
match.block('Graph'), | ||
match.block('Function'), | ||
match.block('Join'), | ||
match.block('CatchBlock', [ | ||
'v0' << match.Parameter(), | ||
match.Branch(match.StrictCompare('v0', match.any, kind: '==='), | ||
ifTrue: 'B6', ifFalse: 'B7'), | ||
]), | ||
'B6' << | ||
match.block('Target', [ | ||
match.Goto('B4'), | ||
]), | ||
'B7' << | ||
match.block('Target', [ | ||
match.ClosureCall(), | ||
match.Goto('B4'), | ||
]), | ||
'B4' << | ||
match.block('Join', [ | ||
match.Return(), | ||
]), | ||
]); | ||
} |
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
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
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
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
Oops, something went wrong.