[CFE] Fix crash in expression compilation caused by having dill builders in source builders scope

This should fix https://github.com/flutter/flutter/issues/97500
and the reproducable part of https://github.com/flutter/devtools/issues/3599

Change-Id: I16b45e4cc8074e0b0a62ae3220d91ae1424bacf3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231004
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
This commit is contained in:
Jens Johansen
2022-01-31 15:34:24 +00:00
committed by Commit Bot
parent 5896462f77
commit 7771ed34cf
4 changed files with 25 additions and 2 deletions
@@ -1731,6 +1731,16 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
}
}
// Setup scope first in two-step process:
// 1) Create a new SourceLibraryBuilder, add imports and setup (import)
// scope.
// 2) Create a new SourceLibraryBuilder, using a nested scope of the scope
// we just created as the scope. The import scopes have been setup via
// the parent chain.
// This is done to create the correct "layering" (i.e. definitions from
// the "self" library first, then imports while not having dill builders
// directly in the scope of a source builder (which can crash things in
// some circumstances).
SourceLibraryBuilder debugLibrary = new SourceLibraryBuilder(
importUri: libraryUri,
fileUri: debugExprUri,
@@ -1784,6 +1794,16 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
debugLibrary.addImportsToScope();
_ticker.logMs("Added imports");
}
debugLibrary = new SourceLibraryBuilder(
importUri: libraryUri,
fileUri: debugExprUri,
packageLanguageVersion:
new ImplicitLanguageVersion(libraryBuilder.library.languageVersion),
loader: lastGoodKernelTarget.loader,
scope: debugLibrary.scope.createNestedScope("expression"),
nameOrigin: libraryBuilder,
isUnsupported: libraryBuilder.isUnsupported,
);
HybridFileSystem hfs =
lastGoodKernelTarget.fileSystem as HybridFileSystem;
@@ -671,6 +671,7 @@ launched
launcher
layer
layered
layering
layers
layout
lc
@@ -1,5 +1,3 @@
# Copyright (c) 2018, 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.
platform_isandroid.expression: Crash
@@ -0,0 +1,4 @@
Errors: {
}
static method /*isLegacy, from org-dartlang-debug:synthetic_debug_expression */ debugExpr() → dynamic
return dart.io::Platform::isAndroid;