Skip to content

Commit d0b2346

Browse files
authored
backport 1.11: fix handling of unknown setting in @constprop, fix error message (#57321)
Backport of PR #56946 to v1.11. Co-authored-by: Shuhei Kadowaki <[email protected]> (cherry picked from commit a3f336f)
1 parent 5c163fc commit d0b2346

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

base/expr.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,14 @@ macro constprop(setting)
400400
end
401401

402402
function constprop_setting(@nospecialize setting)
403+
s = setting
403404
isa(setting, QuoteNode) && (setting = setting.value)
404405
if setting === :aggressive
405406
return :aggressive_constprop
406407
elseif setting === :none
407408
return :no_constprop
408409
end
409-
throw(ArgumentError(LazyString("@constprop "), setting, "not supported"))
410+
throw(ArgumentError(LazyString("`Base.@constprop ", s, "` not supported")))
410411
end
411412

412413
"""

test/misc.jl

+12
Original file line numberDiff line numberDiff line change
@@ -1575,3 +1575,15 @@ end
15751575
end
15761576
@test !occursin("loop not unrolled", out_err)
15771577
end
1578+
1579+
@testset "`@constprop`, `@assume_effects` handling of an unknown setting" begin
1580+
for x ("constprop", "assume_effects")
1581+
try
1582+
eval(Meta.parse("Base.@$x :unknown f() = 3"))
1583+
error("unexpectedly reached")
1584+
catch e
1585+
e::LoadError
1586+
@test e.error isa ArgumentError
1587+
end
1588+
end
1589+
end

0 commit comments

Comments
 (0)