mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
[ddc] Fix assert location in expression eval
When assertions appear in a debugger expression they now have a synthetic source location available. This also allows for the lookup of the actual source. Issue: https://github.com/dart-lang/sdk/issues/43986 Fixes: https://github.com/dart-lang/sdk/issues/54956 Change-Id: I34ae5f810593b40282929d02cb290de86603922f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356287 Reviewed-by: Sigmund Cherem <sigmund@google.com> Commit-Queue: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
parent
97369d0903
commit
98a3605562
2 changed files with 14 additions and 14 deletions
|
@ -4075,23 +4075,23 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
|
||||
SourceLocation? location;
|
||||
late String conditionSource;
|
||||
if (node.location != null) {
|
||||
var encodedSource =
|
||||
node.enclosingComponent!.uriToSource[node.location!.file]!.source;
|
||||
var assertLocation = node.location;
|
||||
if (assertLocation != null) {
|
||||
var fileUri = assertLocation.file;
|
||||
var encodedSource = node.enclosingComponent!.uriToSource[fileUri]!.source;
|
||||
var source = utf8.decode(encodedSource, allowMalformed: true);
|
||||
|
||||
conditionSource =
|
||||
source.substring(node.conditionStartOffset, node.conditionEndOffset);
|
||||
// Assertions that appear in debugger expressions have a synthetic Uri
|
||||
// that is different than the current library where the expression will
|
||||
// be evaluated.
|
||||
var savedUri = _currentUri;
|
||||
_currentUri = fileUri;
|
||||
location = _toSourceLocation(node.conditionStartOffset)!;
|
||||
_currentUri = savedUri;
|
||||
} else {
|
||||
// Location is null in expression compilation when modules
|
||||
// are loaded from kernel using expression compiler worker.
|
||||
// Show the error only in that case, with the condition AST
|
||||
// instead of the source.
|
||||
//
|
||||
// TODO(annagrin): Can we add some information to the kernel,
|
||||
// or add better printing for the condition?
|
||||
// Issue: https://github.com/dart-lang/sdk/issues/43986
|
||||
// If the location is ever null, only show the error with the condition
|
||||
// AST instead of the source.
|
||||
conditionSource = node.condition.toString();
|
||||
}
|
||||
return js.statement(' if (!#) #;', [
|
||||
|
|
|
@ -58,8 +58,8 @@ void main(List<String> args) async {
|
|||
expression: '() { assert(false); return 0; } ()',
|
||||
expectedError: allOf(
|
||||
contains('Error: Assertion failed:'),
|
||||
contains('<unknown source>:-1:-1'),
|
||||
contains('BoolLiteral(false)'),
|
||||
contains('org-dartlang-debug:synthetic_debug_expression:1:13'),
|
||||
contains('false'),
|
||||
contains('is not true'),
|
||||
));
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue