From 55d0f2f23f02c0e5bb5b7f31d324dcd549ef02b9 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Sat, 12 Sep 2020 15:05:27 +0000 Subject: [PATCH 1/3] Work around flow analysis bug Flow analysis currently has a bug preventing for-each loop variables from being properly promoted in the presence of closures (https://github.com/dart-lang/sdk/issues/43136); as a result of this bug the source_span package had two non-null assertions that ought to have been unnecessary. I'm preparing a fix for that bug, however if I land it as is, it will cause the front end to emit errors saying "Operand of null-aware operation '!' has type '_Highlight' which excludes null"; this in turn will cause SDK bot breakages (since source_span is imported into the SDK repo). So, in order to land the fix, we need to first update the source_span package to work around the bug; this change does that by allocating a temporary variable (which *is* promoted correctly). Once the fix for https://github.com/dart-lang/sdk/issues/43136 lands, I will make a follow-up change that deletes the temporary variable. --- lib/src/highlighter.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/src/highlighter.dart b/lib/src/highlighter.dart index d61ff9f..c3b0934 100644 --- a/lib/src/highlighter.dart +++ b/lib/src/highlighter.dart @@ -292,7 +292,8 @@ class Highlighter { ? _primaryColor : _secondaryColor; var foundCurrent = false; - for (var highlight in highlightsByColumn) { + for (var tmp in highlightsByColumn) { + var highlight = tmp; // Work around https://github.com/dart-lang/sdk/issues/43136 final startLine = highlight?.span.start.line; final endLine = highlight?.span.end.line; if (current != null && highlight == current) { @@ -326,9 +327,9 @@ class Highlighter { }, color: openedOnThisLineColor); openedOnThisLine = true; openedOnThisLineColor ??= - highlight!.isPrimary ? _primaryColor : _secondaryColor; + highlight.isPrimary ? _primaryColor : _secondaryColor; } else if (endLine == line.number && - highlight!.span.end.column == line.text.length) { + highlight.span.end.column == line.text.length) { _buffer.write(highlight.label == null ? glyph.glyphOrAscii('└', '\\') : vertical); From 779ad6de164bf30eb2b56947d7341074d17430a0 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Sat, 12 Sep 2020 21:12:09 +0000 Subject: [PATCH 2/3] Change to `final` to satisfy lint --- lib/src/highlighter.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/highlighter.dart b/lib/src/highlighter.dart index c3b0934..9d40595 100644 --- a/lib/src/highlighter.dart +++ b/lib/src/highlighter.dart @@ -293,7 +293,7 @@ class Highlighter { : _secondaryColor; var foundCurrent = false; for (var tmp in highlightsByColumn) { - var highlight = tmp; // Work around https://github.com/dart-lang/sdk/issues/43136 + final highlight = tmp; // Work around https://github.com/dart-lang/sdk/issues/43136 final startLine = highlight?.span.start.line; final endLine = highlight?.span.end.line; if (current != null && highlight == current) { From 7b6267a9aaa1ac2ac7c0f127fe41b6538164cb2d Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Sat, 12 Sep 2020 21:30:28 +0000 Subject: [PATCH 3/3] Adjust comment to satisfy dartfmt --- lib/src/highlighter.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/highlighter.dart b/lib/src/highlighter.dart index 9d40595..1c39185 100644 --- a/lib/src/highlighter.dart +++ b/lib/src/highlighter.dart @@ -293,7 +293,8 @@ class Highlighter { : _secondaryColor; var foundCurrent = false; for (var tmp in highlightsByColumn) { - final highlight = tmp; // Work around https://github.com/dart-lang/sdk/issues/43136 + // Work around https://github.com/dart-lang/sdk/issues/43136 + final highlight = tmp; final startLine = highlight?.span.start.line; final endLine = highlight?.span.end.line; if (current != null && highlight == current) {