diff --git a/src/flint/FlintTypes.jl b/src/flint/FlintTypes.jl index bb6b01550c..cba144d6d2 100644 --- a/src/flint/FlintTypes.jl +++ b/src/flint/FlintTypes.jl @@ -2237,7 +2237,9 @@ See [`FqPolyRepField`](@ref) for $p$ being a [`ZZRingElem`](@ref). See [`fqPolyR overfields :: Dict{Int, Vector{FinFieldMorphism}} subfields :: Dict{Int, Vector{FinFieldMorphism}} - function fqPolyRepField(c::ZZRingElem, deg::Int, s::Symbol, cached::Bool = true) + function fqPolyRepField(c::ZZRingElem, deg::Int, s::Symbol, cached::Bool = true; check::Bool = true) + check && !is_prime(c) && + throw(DomainError(c, "the characteristic must be a prime")) return get_cached!(FqNmodFiniteFieldID, (c, deg, s), cached) do d = new() ccall((:fq_nmod_ctx_init, libflint), Nothing, @@ -2646,7 +2648,9 @@ if NEW_FLINT overfields :: Dict{Int, Vector{FinFieldMorphism}} subfields :: Dict{Int, Vector{FinFieldMorphism}} - function FqPolyRepField(char::ZZRingElem, deg::Int, s::Symbol, cached::Bool = true) + function FqPolyRepField(char::ZZRingElem, deg::Int, s::Symbol, cached::Bool = true; check::Bool = true) + check && !is_probable_prime(char) && + throw(DomainError(char, "the characteristic must be a prime")) return get_cached!(FqFiniteFieldID, (char, deg, s), cached) do d = new() finalizer(_FqFiniteField_clear_fn, d) @@ -2717,7 +2721,9 @@ else overfields :: Dict{Int, Vector{FinFieldMorphism}} subfields :: Dict{Int, Vector{FinFieldMorphism}} - function FqPolyRepField(char::ZZRingElem, deg::Int, s::Symbol, cached::Bool = true) + function FqPolyRepField(char::ZZRingElem, deg::Int, s::Symbol, cached::Bool = true; check::Bool = true) + check && !is_probable_prime(char) && + throw(DomainError(char, "the characteristic must be a prime")) return get_cached!(FqFiniteFieldID, (char, deg, s), cached) do d = new() finalizer(_FqFiniteField_clear_fn, d) diff --git a/test/flint/fq-test.jl b/test/flint/fq-test.jl index 19768aedca..17ab001b3b 100644 --- a/test/flint/fq-test.jl +++ b/test/flint/fq-test.jl @@ -258,3 +258,8 @@ end R, x = finite_field(ZZ(19), 3, "x") @test R([1, 0, 1]) == x^2 + 1 end + +@testset "Nemo.jl#1493" begin + @test_throws DomainError GF(ZZ(4), 2) + @test_throws DomainError finite_field(ZZ(6), 2, "x") +end diff --git a/test/flint/fq_nmod-test.jl b/test/flint/fq_nmod-test.jl index dd6a689bf7..24cd3a600a 100644 --- a/test/flint/fq_nmod-test.jl +++ b/test/flint/fq_nmod-test.jl @@ -270,3 +270,8 @@ end R, x = finite_field(19, 3, "x") @test R([1, 0, 1]) == x^2 + 1 end + +@testset "Nemo.jl#1493" begin + @test_throws DomainError GF(4, 2) + @test_throws DomainError finite_field(6, 2, "x") +end