commit | cc7c4288a83f71ecef3414199947b52a8c112c65 | [log] [tgz] |
---|---|---|
author | Paul Berry <stereotype441@gmail.com> | Mon Sep 14 10:07:56 2020 -0700 |
committer | GitHub <noreply@github.com> | Mon Sep 14 10:07:56 2020 -0700 |
tree | 47d295aefc23ba187cc93a92fc4505bfd7002f04 | |
parent | 7e7992f9613e08dd6cd2a071384359118978b7fb [diff] |
Work around flow analysis bug (#59) 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.
source_span
is a library for tracking locations in source code. It's designed to provide a standard representation for source code locations and spans so that disparate packages can easily pass them among one another, and to make it easy to generate human-friendly messages associated with a given piece of code.
The most commonly-used class is the package's namesake, SourceSpan
. It represents a span of characters in some source file, and is often attached to an object that has been parsed to indicate where it was parsed from. It provides access to the text of the span via SourceSpan.text
and can be used to produce human-friendly messages using SourceSpan.message()
.
When parsing code from a file, SourceFile
is useful. Not only does it provide an efficient means of computing line and column numbers, SourceFile.span()
returns special FileSpan
s that are able to provide more context for their error messages.