Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
Work around flow analysis bug (#59)
Browse files Browse the repository at this point in the history
Flow analysis currently has a bug preventing for-each loop variables
from being properly promoted in the presence of closures
(dart-lang/sdk#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 dart-lang/sdk#43136 lands,
I will make a follow-up change that deletes the temporary variable.
  • Loading branch information
stereotype441 authored Sep 14, 2020
1 parent 7e7992f commit cc7c428
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/src/highlighter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ class Highlighter {
? _primaryColor
: _secondaryColor;
var foundCurrent = false;
for (var highlight in highlightsByColumn) {
for (var tmp in highlightsByColumn) {
// 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) {
Expand Down Expand Up @@ -326,9 +328,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);
Expand Down

0 comments on commit cc7c428

Please sign in to comment.