Skip to content

Commit

Permalink
Enable Aqua.jl's ambiguity check (#936)
Browse files Browse the repository at this point in the history
* Remove `(::<AbstractString)(::GapObj)`

* Fix all calls of it

* Toggle Aqua switch
  • Loading branch information
lgoettgens authored Sep 22, 2023
1 parent dfc41a3 commit 6bafdba
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pkg/JuliaInterface/tst/convert.tst
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ gap> ForAll([0..64], n -> Julia.GAP.Obj( -big2^n ) = -2^n);
true

#
gap> string := GAPToJulia( Julia.Base.AbstractString, "bla" );
gap> string := GAPToJulia( Julia.Base.String, "bla" );
<Julia: "bla">
gap> JuliaToGAP( IsString, string );
"bla"
Expand Down Expand Up @@ -221,7 +221,7 @@ Error, <obj> must be a Julia range
## empty list vs. empty string
gap> emptylist:= GAPToJulia( JuliaEvalString( "Vector{Any}"), [] );
<Julia: Any[]>
gap> emptystring:= GAPToJulia( Julia.Base.AbstractString, "" );
gap> emptystring:= GAPToJulia( Julia.Base.String, "" );
<Julia: "">
gap> JuliaToGAP( IsList, emptylist );
[ ]
Expand Down
1 change: 0 additions & 1 deletion src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ function String(obj::GapObj)
Wrappers.IsString(obj) && return CSTR_STRING(Wrappers.CopyToStringRep(obj))
throw(ConversionError(obj, String))
end
(::Type{T})(obj::GapObj) where {T<:AbstractString} = convert(T, String(obj))

"""
Symbol(obj::GapObj)
Expand Down
3 changes: 1 addition & 2 deletions src/gap_to_julia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ gap_to_julia(::Type{Cuchar}, obj::GapObj) = Cuchar(obj)

## Strings
gap_to_julia(::Type{String}, obj::GapObj) = String(obj)
gap_to_julia(::Type{T}, obj::GapObj) where {T<:AbstractString} = T(obj)

## Symbols
gap_to_julia(::Type{Symbol}, obj::GapObj) = Symbol(obj)
Expand Down Expand Up @@ -333,7 +332,7 @@ function gap_to_julia(x::GapObj; recursive::Bool = true)
GAP_IS_MACFLOAT(x) && return gap_to_julia(Float64, x)
GAP_IS_CHAR(x) && return gap_to_julia(Cuchar, x)
# Do not choose this conversion for other lists in 'IsString'.
Wrappers.IsStringRep(x) && return gap_to_julia(AbstractString, x)
Wrappers.IsStringRep(x) && return gap_to_julia(String, x)
# Do not choose this conversion for other lists in 'IsRange'.
Wrappers.IsRangeRep(x) && return gap_to_julia(StepRange{Int64,Int64}, x)
# Do not choose this conversion for other lists in 'IsBlist'.
Expand Down
2 changes: 1 addition & 1 deletion test/Aqua.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Aqua
@testset "Aqua.jl" begin
Aqua.test_all(
GAP;
ambiguities=false, # TODO: fix ambiguities
ambiguities=true,
unbound_args=true,
undefined_exports=true,
project_extras=true,
Expand Down
2 changes: 1 addition & 1 deletion test/basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ end

@test_throws ErrorException GAP.Globals.FOOBARQUX

str = GAP.gap_to_julia(AbstractString, GAP.ValueGlobalVariable("IdentifierLetters"))
str = GAP.gap_to_julia(String, GAP.ValueGlobalVariable("IdentifierLetters"))
@test str == "0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"

@test GAP.CanAssignGlobalVariable("Read") == false
Expand Down
3 changes: 1 addition & 2 deletions test/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,13 @@
@test (@inferred String(x)) == "abc"
x = GAP.evalstr("\"foo\"")
@test (@inferred String(x)) == "foo"
@test AbstractString(x) == "foo"
end

@testset "Symbols" begin
x = GAP.evalstr("\"foo\"")
@test (@inferred Symbol(x)) == :foo
x = GAP.evalstr("(1,2,3)")
@test_throws GAP.ConversionError AbstractString(x)
@test_throws GAP.ConversionError String(x)

# Convert GAP string to Vector{UInt8} (==Vector{UInt8})
x = GAP.evalstr("\"foo\"")
Expand Down
3 changes: 1 addition & 2 deletions test/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
@test (@inferred GAP.gap_to_julia(String, x)) == "abc"
x = GAP.evalstr("\"foo\"")
@test (@inferred GAP.gap_to_julia(String, x)) == "foo"
@test GAP.gap_to_julia(AbstractString, x) == "foo"
@test GAP.gap_to_julia(x) == "foo"
x = "abc\000def"
@test GAP.gap_to_julia(GAP.julia_to_gap(x)) == x
Expand All @@ -102,7 +101,7 @@
x = GAP.evalstr("\"foo\"")
@test (@inferred GAP.gap_to_julia(Symbol, x)) == :foo
x = GAP.evalstr("(1,2,3)")
@test_throws GAP.ConversionError GAP.gap_to_julia(AbstractString, x)
@test_throws GAP.ConversionError GAP.gap_to_julia(String, x)

# Convert GAP string to Vector{UInt8} (==Vector{UInt8})
x = GAP.evalstr("\"foo\"")
Expand Down

0 comments on commit 6bafdba

Please sign in to comment.