Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force variables to be different in @varnames_interface #1850

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/misc/VarNames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ function varnames_method(d::Dict{Symbol})
$f($(args...), s1::VarNames, s::VarNames...; kv...) where {$(wheres...)} =
$f($(argnames...), (s1, s...); kv...)
function $f($(args...), s::Tuple{Vararg{VarNames}}; kv...) where {$(wheres...)}
X, gens = $f($(argnames...), variable_names(s...); kv...)
varnames = variable_names(s...)
@req allunique(varnames) "Variable names must be unique"
X, gens = $f($(argnames...), varnames; kv...)
return X, reshape_to_varnames(gens, s...)...
end
end
Expand Down Expand Up @@ -450,6 +452,14 @@ julia> @f("hello", "x#" => (1:1, 1:2), "y#" => (1:2), [:z])
julia> (x11, x12, y1, y2, z)
("x11", "x12", "y1", "y2", "z")

julia> f("something", VarName["x", "y", "z", :x])
ERROR: ArgumentError: Variable names must be unique
[...]

julia> f("something else", :x=>1:2, :x=>1:3)
ERROR: ArgumentError: Variable names must be unique
[...]

julia> g(a, s::Vector{Symbol}; kv...) = (a, kv...), String.(s)
g (generic function with 1 method)

Expand Down
Loading