From b2ab29e6ba8d3aad4b568584ef71ac3a5a41ae45 Mon Sep 17 00:00:00 2001 From: Lilith Orion Hafner Date: Mon, 16 Sep 2024 07:46:46 -0500 Subject: [PATCH] Don't assume that `SubString` has `pointer` and copy instead Still assume `Substring{String}` has `pointer` Add tests --- src/parse_stream.jl | 2 +- test/parse_stream.jl | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/parse_stream.jl b/src/parse_stream.jl index 8aad71df..fe10b333 100644 --- a/src/parse_stream.jl +++ b/src/parse_stream.jl @@ -391,7 +391,7 @@ function ParseStream(text::String, index::Integer=1; version=VERSION) ParseStream(unsafe_wrap(Vector{UInt8}, text), text, index, version) end -function ParseStream(text::SubString, index::Integer=1; version=VERSION) +function ParseStream(text::SubString{String}, index::Integer=1; version=VERSION) # See also IOBuffer(SubString("x")) ParseStream(unsafe_wrap(Vector{UInt8}, pointer(text), sizeof(text)), text, index, version) diff --git a/test/parse_stream.jl b/test/parse_stream.jl index f7c0bd60..1ef70cfd 100644 --- a/test/parse_stream.jl +++ b/test/parse_stream.jl @@ -7,7 +7,10 @@ using JuliaSyntax: ParseStream, peek, peek_token, bump, bump_trivia, bump_invisible, emit, emit_diagnostic, TRIVIA_FLAG, INFIX_FLAG, - ParseStreamPosition, first_child_position, last_child_position + ParseStreamPosition, first_child_position, last_child_position, + parsestmt + +import InlineStrings # Here we manually issue parse events in the order the Julia parser would issue # them @@ -147,3 +150,10 @@ end @test first_child_position(st, position(st)) == ParseStreamPosition(4, 1) @test last_child_position(st, position(st)) == ParseStreamPosition(7, 2) end + +@testset "SubString{String3} (issue #505)" begin + x = split(InlineStrings.InlineString("1 2"))[1] + @test x == "1" + @test ParseStream(x) isa ParseStream + @test parsestmt(Expr, x) == parsestmt(Expr, "1") +end