File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ Standard library changes
101101* TCP socket objects now expose ` closewrite ` functionality and support half-open mode usage ([ #40783 ] ).
102102* Intersect returns a result with the eltype of the type-promoted eltypes of the two inputs ([ #41769 ] ).
103103* ` Iterators.countfrom ` now accepts any type that defines ` + ` . ([ #37747 ] )
104+ * The ` LazyString ` and the ` lazy"str" ` macro were added to support delayed construction of error messages in error paths. ([ #33711 ] )
104105
105106#### InteractiveUtils
106107* A new macro ` @time_imports ` for reporting any time spent importing packages and their dependencies ([ #41612 ] )
Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ of functions).
88
99This type is designed to be cheap to construct at runtime, trying to offload
1010as much work as possible to either the macro or later printing operations.
11+
12+ !!! compat "Julia 1.8"
13+ `LazyString` requires Julia 1.8 or later.
1114"""
1215mutable struct LazyString <: AbstractString
1316 parts:: Tuple
@@ -16,6 +19,16 @@ mutable struct LazyString <: AbstractString
1619 LazyString (args... ) = new (args)
1720end
1821
22+ """
23+ lazy"str"
24+
25+ Create a [`LazyString`](@ref) using regular string interpolation syntax.
26+ Note that interpolations are *evaluated* at LazyString construction time,
27+ but *printing* is delayed until the first access to the string.
28+
29+ !!! compat "Julia 1.8"
30+ `lazy"str"` requires Julia 1.8 or later.
31+ """
1932macro lazy_str (text)
2033 parts = Any[]
2134 lastidx = idx = 1
Original file line number Diff line number Diff line change @@ -1094,3 +1094,10 @@ end
10941094 @test sprint (summary, SubString (" foα" , 2 )) == " 3-codeunit SubString{String}"
10951095 @test sprint (summary, " " ) == " empty String"
10961096end
1097+
1098+ @testset " LazyString" begin
1099+ @test repr (lazy " $(1+2) is 3" ) == " \" 3 is 3\" "
1100+ let d = Dict (lazy " $(1+2) is 3" => 3 )
1101+ @test d[" 3 is 3" ] == 3
1102+ end
1103+ end
You can’t perform that action at this time.
0 commit comments