Skip to content

Commit 8f83286

Browse files
committed
Fix despecialisation of annotations list
In f117a50 code modifying annotations via list comprehensions was introduced. However, when (1) there are annotations present and (2) all annotations are filtered out, this comprehension is inferred to a wider type incompatible with the AnnotatedString constructor. This can be fixed by changing the first element of the tuple to directly use the UnitRange{Int} constructor, which stops it being inferred as an Any.
1 parent 6e7db14 commit 8f83286

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

base/strings/annotated.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ function read(io::AnnotatedIOBuffer, ::Type{AnnotatedString{T}}) where {T <: Abs
486486
if (start = position(io)) == 0
487487
AnnotatedString(read(io.io, T), copy(io.annotations))
488488
else
489-
annots = [(max(1, first(region) - start):last(region)-start, val)
489+
annots = [(UnitRange{Int}(max(1, first(region) - start), last(region)-start), val)
490490
for (region, val) in io.annotations if last(region) > start]
491491
AnnotatedString(read(io.io, T), annots)
492492
end

test/strings/annotated.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ end
122122
@test read(seek(aio, 1), Base.AnnotatedString) == Base.AnnotatedString("ello world", [(1:4, :tag => 1), (6:10, :tag => 2)])
123123
@test read(seek(aio, 4), Base.AnnotatedString) == Base.AnnotatedString("o world", [(1:1, :tag => 1), (3:7, :tag => 2)])
124124
@test read(seek(aio, 5), Base.AnnotatedString) == Base.AnnotatedString(" world", [(2:6, :tag => 2)])
125+
@test read(aio, Base.AnnotatedString) == Base.AnnotatedString("")
125126
@test read(seekstart(truncate(deepcopy(aio), 5)), Base.AnnotatedString) == Base.AnnotatedString("hello", [(1:5, :tag => 1)])
126127
@test read(seekstart(truncate(deepcopy(aio), 6)), Base.AnnotatedString) == Base.AnnotatedString("hello ", [(1:5, :tag => 1)])
127128
@test read(seekstart(truncate(deepcopy(aio), 7)), Base.AnnotatedString) == Base.AnnotatedString("hello w", [(1:5, :tag => 1), (7:7, :tag => 2)])

0 commit comments

Comments
 (0)