mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:19:49 +00:00
[ddc] Fix the use of the wrong null literal
This code should be using a `LiteralNull` from the JS AST but was accidentally using the `NullLiteral` from the Kernel AST. Add a test to trigger this code path in the expression compiler because there must not be a source location for the code being compiled. Add a retry duration for getting a chrome tab in the test suite. This fixes a failure I was seeing when I run the test locally. Change-Id: I6900ace6280f1105c77ccafce4f47d0fc5771d6b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252540 Reviewed-by: Anna Gringauze <annagrin@google.com> Commit-Queue: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
parent
38dc6e7dc8
commit
901d01a45c
|
@ -3646,7 +3646,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
runtimeCall('nullFailed(#, #, #, #)', [
|
||||
location != null
|
||||
? _cacheUri(location.file.toString())
|
||||
: NullLiteral(),
|
||||
: js_ast.LiteralNull(),
|
||||
js.number(location?.line ?? -1),
|
||||
js.number(location?.column ?? -1),
|
||||
js.escapedString('${p.name}')
|
||||
|
|
|
@ -357,6 +357,34 @@ void runNullSafeSharedTests(SetupCompilerOptions setup, TestDriver driver) {
|
|||
});
|
||||
});
|
||||
|
||||
group('Automatically inserted argument null checks', () {
|
||||
var source = r'''
|
||||
main() {
|
||||
// Breakpoint: bp
|
||||
print('hello world');
|
||||
}
|
||||
''';
|
||||
|
||||
setUpAll(() async {
|
||||
await driver.initSource(setup, source);
|
||||
});
|
||||
|
||||
tearDownAll(() async {
|
||||
await driver.cleanupTest();
|
||||
});
|
||||
|
||||
test('do not cause a crash in the expression compiler', () async {
|
||||
// Compiling an expression that contains a method with a non-nullable
|
||||
// parameter was causing a compiler crash due to the lack of a source
|
||||
// location and the use of the wrong null literal value. This verifies
|
||||
// the expression compiler can safely compile this pattern.
|
||||
await driver.check(
|
||||
breakpointId: 'bp',
|
||||
expression: '((){bool fn(bool b) {return b;} return fn(true);})()',
|
||||
expectedResult: 'true');
|
||||
});
|
||||
});
|
||||
|
||||
group('Synthetic variables', () {
|
||||
var source = r'''
|
||||
dynamic couldReturnNull() => null;
|
||||
|
@ -376,7 +404,7 @@ void runNullSafeSharedTests(SetupCompilerOptions setup, TestDriver driver) {
|
|||
await driver.cleanupTest();
|
||||
});
|
||||
|
||||
test('do not cause a crash the expression compiler', () async {
|
||||
test('do not cause a crash in the expression compiler', () async {
|
||||
// The null aware code in the test source causes the compiler to introduce
|
||||
// a let statement that includes a synthetic variable declaration.
|
||||
// That variable has no name and was causing a crash in the expression
|
||||
|
|
|
@ -266,8 +266,9 @@ class TestDriver {
|
|||
}
|
||||
|
||||
// Connect to the first 'normal' tab.
|
||||
var tab = await chrome.chromeConnection
|
||||
.getTab((tab) => !tab.isBackgroundPage && !tab.isChromeExtension);
|
||||
var tab = await chrome.chromeConnection.getTab(
|
||||
(tab) => !tab.isBackgroundPage && !tab.isChromeExtension,
|
||||
retryFor: Duration(seconds: 5));
|
||||
if (tab == null) {
|
||||
throw Exception('Unable to connect to Chrome tab');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue