Skip to content

promote causes segfault or StackOverflow with bad promote_rules #19968

Closed
@omus

Description

@omus

I was messing around with a toy promote_rule example and I discovered a segfault on Julia 0.5 and StackOverflow in Julia 0.6

julia> type ModInt{n} <: Integer
               k::Int
               ModInt(k::Integer) = new(mod(k,n))
       end

julia> Base.promote_rule{n}(::Type{ModInt{n}}, ::Type{Int}) = ModInt{n}

julia> Base.promote_rule{n}(::Type{Int}, ::Type{ModInt{n}}) = Int

Julia 0.5

julia> promote(ModInt{4}(6), 7)
Segmentation fault: 11

Julia 0.6

julia> promote(ModInt{4}(6), 7)
ERROR: StackOverflowError:
Stacktrace:
 [1] promote_type(::Type{ModInt{4}}, ::Type{Int64}) at ./promotion.jl:149 (repeats 80000 times)

Metadata

Metadata

Assignees

No one assigned

    Labels

    types and dispatchTypes, subtyping and method dispatch

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions