Skip to content

Commit

Permalink
Fix handling of kwargs in @polynomial_ring (Nemocas#1632)
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin authored Feb 29, 2024
1 parent 52fc7cb commit 42192d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/misc/VarNames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,12 @@ function varnames_macro(f, args_count, opt_in)
# Keyword arguments after `;` end up in `kv`.
# Those without previous `;` get evaluated and end up in `kv2`.
# Note: one could work around evaluating the latter if necessary.
kv = Meta.isexpr(first(args), :parameters) ?
popfirst!(args).args : Expr(:parameters)
if Meta.isexpr(first(args), :parameters)
kv = first(args)
args = args[2:end]
else
kv = Expr(:parameters)
end

req(length(args) >= $args_count+1, "Not enough arguments")
base_args = args[1:$args_count]
Expand Down
11 changes: 11 additions & 0 deletions test/generic/MPoly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@
QQxxx3 = @polynomial_ring(QQ, :x=>1:3)
@test QQxxx_ == (QQxxx3, [x1, x2, x3])

# test support of kwargs
QQxxx4 = @polynomial_ring(QQ, "x#" => 1:3; internal_ordering=:lex)
@test QQxxx_ == (QQxxx4, [x1, x2, x3])

QQxxx_deglex_ = @inferred polynomial_ring(QQ, "x#" => 1:3; internal_ordering=:deglex)
@test internal_ordering(QQxxx_deglex_[1]) == :deglex

QQxxx_deglex2 = @polynomial_ring(QQ, "x#" => 1:3; internal_ordering=:deglex)
@test internal_ordering(QQxxx_deglex2) == :deglex
@test QQxxx_deglex_ == (QQxxx_deglex2, [x1, x2, x3])

ZZxy_ = @inferred polynomial_ring(ZZ, :x => (1:2, 1:2), :y => 0:3)

ZZxy2_ = @inferred polynomial_ring(ZZ, :x => ["1, 1" "1, 2"; "2, 1" "2, 2"], :y => (0:3,))
Expand Down

0 comments on commit 42192d8

Please sign in to comment.