Skip to content

Commit ad5e2b9

Browse files
authored
Don't assume that SubString has pointer and copy instead (#506)
* Don't assume that `SubString` has `pointer` and copy instead * Still assume `Substring{String}` has `pointer` * Test with `Test.GenericString`
1 parent 98c202a commit ad5e2b9

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/parse_stream.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ function ParseStream(text::String, index::Integer=1; version=VERSION)
391391
ParseStream(unsafe_wrap(Vector{UInt8}, text),
392392
text, index, version)
393393
end
394-
function ParseStream(text::SubString, index::Integer=1; version=VERSION)
394+
function ParseStream(text::SubString{String}, index::Integer=1; version=VERSION)
395395
# See also IOBuffer(SubString("x"))
396396
ParseStream(unsafe_wrap(Vector{UInt8}, pointer(text), sizeof(text)),
397397
text, index, version)

test/parse_stream.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ using JuliaSyntax: ParseStream,
77
peek, peek_token,
88
bump, bump_trivia, bump_invisible,
99
emit, emit_diagnostic, TRIVIA_FLAG, INFIX_FLAG,
10-
ParseStreamPosition, first_child_position, last_child_position
10+
ParseStreamPosition, first_child_position, last_child_position,
11+
parsestmt
1112

1213
# Here we manually issue parse events in the order the Julia parser would issue
1314
# them
@@ -147,3 +148,13 @@ end
147148
@test first_child_position(st, position(st)) == ParseStreamPosition(4, 1)
148149
@test last_child_position(st, position(st)) == ParseStreamPosition(7, 2)
149150
end
151+
152+
@testset "SubString{GenericString} (issue #505)" begin
153+
x = Test.GenericString("1 2")
154+
@test x == "1 2"
155+
y = split(x)[1]
156+
@test y == "1"
157+
@test y isa SubString{GenericString}
158+
@test ParseStream(y) isa ParseStream
159+
@test parsestmt(Expr, y) == parsestmt(Expr, "1")
160+
end

0 commit comments

Comments
 (0)