Skip to content

Commit

Permalink
equiv_typedef: don't reject equivalence just for gensyms
Browse files Browse the repository at this point in the history
This fixes the following:

```
julia> struct Symmetric{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}
           data::S
           uplo::Char
       end

julia> struct Symmetric{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}
           data::S
           uplo::Char
       end
ERROR: invalid redefinition of constant Symmetric
```

`Core._equiv_typedef` returns false which ends up triggering the error.
  • Loading branch information
timholy committed Feb 23, 2021
1 parent 3129a5b commit af8ff73
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ static int equiv_type(jl_value_t *ta, jl_value_t *tb)
while (jl_is_unionall(a)) {
jl_unionall_t *ua = (jl_unionall_t*)a;
jl_unionall_t *ub = (jl_unionall_t*)b;
if (!jl_egal(ua->var->lb, ub->var->lb) || !jl_egal(ua->var->ub, ub->var->ub) ||
if (!jl_types_egal(ua->var->lb, ub->var->lb) || !jl_types_egal(ua->var->ub, ub->var->ub) ||
ua->var->name != ub->var->name)
goto no;
a = jl_instantiate_unionall(ua, (jl_value_t*)ub->var);
Expand Down
16 changes: 16 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7289,12 +7289,28 @@ end

# issue #36104
module M36104
using Test
struct T36104
v::Vector{M36104.T36104}
end
struct T36104 # check that redefining it works, issue #21816
v::Vector{T36104}
end
# with a gensymmed unionall
struct Symmetric{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}
data::S
uplo::Char
end
struct Symmetric{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}
data::S
uplo::Char
end
@test_throws ErrorException begin
struct Symmetric{T,S<:AbstractMatrix{T}} <: AbstractMatrix{T}
data::S
uplo::Char
end
end
end
@test fieldtypes(M36104.T36104) == (Vector{M36104.T36104},)
@test_throws ErrorException("expected") @eval(struct X36104; x::error("expected"); end)
Expand Down

0 comments on commit af8ff73

Please sign in to comment.