Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

promote_type should fail more gracefully #38310

Closed
jonniedie opened this issue Nov 5, 2020 · 1 comment
Closed

promote_type should fail more gracefully #38310

jonniedie opened this issue Nov 5, 2020 · 1 comment

Comments

@jonniedie
Copy link
Contributor

It's pretty easy to mistakenly define promote_type methods when you meant to define promote_rule methods. This can produce a fatal error in some cases, though:

julia> struct MyType{T}
           a::T
       end

julia> Base.promote_type(::Type{<:MyType}, ::Type{T}) where {T<:Number} = MyType{T}

fatal: error thrown and no exception handler available.
MethodError(f=typeof(Base.promote_type)(), args=(Core.TypeofBottom(), Int64), world=0x0000000000006cd8)
jl_method_error_bare at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:1798
jl_method_error at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:1816
jl_lookup_generic_ at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:2373
jl_apply_generic at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:2394
promote_result at .\promotion.jl:237 [inlined]
promote_type at .\promotion.jl:223 [inlined]
promote_typeof at .\promotion.jl:262 [inlined]
+ at .\int.jl:919
threadid at .\threadingconstructs.jl:10
task_done_hook at .\task.jl:432
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1690 [inlined]
jl_finish_task at /cygdrive/d/buildbot/worker/package_win64/build/src\task.c:198
start_task at /cygdrive/d/buildbot/worker/package_win64/build/src\task.c:717
error in running finalizer: MethodError(f=typeof(Base.promote_type)(), args=(Core.TypeofBottom(), Int64), world=0x0000000000006cd8)
error in running finalizer: MethodError(f=typeof(Base.promote_type)(), args=(Core.TypeofBottom(), Int64), world=0x0000000000006cd8)
julia> versioninfo()
Julia Version 1.5.2
Commit 539f3ce943 (2020-09-23 23:17 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Xeon(R) E-2276M  CPU @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
@JeffBezanson
Copy link
Member

I think this case should be handled with sealed functions (#31222), so adding this method would be disallowed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants