# Fatal error when .jl file included

**URL:** https://discourse.julialang.org/t/fatal-error-when-jl-file-included/19946
**Category:** New to Julia
**Tags:** question
**Created:** [January 22, 2019, 8:47pm UTC](https://discourse.julialang.org/t/fatal-error-when-jl-file-included/19946 "2019-01-22T20:47:50Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dan123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan123/32/5724_2.png) [@dan123](https://discourse.julialang.org/u/dan123)
#### Post date: [January 22, 2019, 8:47pm UTC](https://discourse.julialang.org/t/fatal-error-when-jl-file-included/19946/1 "2019-01-22T20:47:50Z")

</div>

I have the following code in a file named badconvert.jl. When included into julia either on the command line or using include(“badconvert.jl”) it produces a fatal error (shown a the end of this message).

This isn’t the actual code I am trying to use, I’ve just tried to reduce the problem down to small example that I could.

I’m using Julia 1.0.0 on macOS. Any hints on what is going wrong is appreciated.

This code produces the error.

```julia
import Base.convert

struct s1
    value::Float64
end

function convert(s1, x::Int64)
    s1(Float64(x))
end

```

However this code works as expected.

```julia
import Base.convert

struct s1
    value::Float64
end

function convert(s1, x::Int16)
    s1(Float64(x))
end

```

The only difference between this examples is the second argument for the convert function is Int64 in the first example and Int16 in the second.

```julia
Daniels-Mac-Pro-2:research danielsullivan$ julia -i badconvert.jl
fatal: error thrown and no exception handler available.
MethodError(f=typeof(Base.convert)(), args=(Int32, 0), world=0x00000000000061b1)
rec_backtrace at /Users/osx/buildbot/slave/package_osx64/build/src/stackwalk.c:94
record_backtrace at /Users/osx/buildbot/slave/package_osx64/build/src/task.c:246 [inlined]
jl_throw at /Users/osx/buildbot/slave/package_osx64/build/src/task.c:577
jl_method_error_bare at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1614
jl_method_error at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1632
jl_lookup_generic_ at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:2159
jl_apply_generic at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:2179
cconvert at ./essentials.jl:344
containsnul at ./c.jl:209
unsafe_convert at ./c.jl:216
_getenv at ./env.jl:40
access_env at ./env.jl:44
get at ./env.jl:77
repl_color at ./client.jl:16
jl_fptr_trampoline at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1829
error_color at ./client.jl:22
display_error at ./client.jl:93
jl_fptr_trampoline at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1829
display_error at ./client.jl:102
jl_fptr_trampoline at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1829
jl_apply at /Users/osx/buildbot/slave/package_osx64/build/src/./julia.h:1536 [inlined]
jl_f__apply at /Users/osx/buildbot/slave/package_osx64/build/src/builtins.c:556
jl_f__apply_latest at /Users/osx/buildbot/slave/package_osx64/build/src/builtins.c:594
#invokelatest#1 at ./essentials.jl:686 [inlined]
invokelatest at ./essentials.jl:685 [inlined]
_start at ./client.jl:423
true_main at /usr/local/bin/julia (unknown line)
main at /usr/local/bin/julia (unknown line)
error in running finalizer: MethodError(f=typeof(Base.convert)(), args=(Int64, 5), world=0x00000000000061b1)
error in running finalizer: MethodError(f=typeof(Base.convert)(), args=(Int64, 5), world=0x00000000000061b1)
error in running finalizer: MethodError(f=typeof(Base.convert)(), args=(Int64, 5), world=0x00000000000061b1)

```

```julia
**julia&gt;** versioninfo()

Julia Version 1.0.0

Commit 5d4eaca0c9 (2018-08-08 20:58 UTC)

Platform Info:

OS: macOS (x86_64-apple-darwin14.5.0)

CPU: Intel(R) Xeon(R) CPU E5-2697 v2 @ 2.70GHz

WORD_SIZE: 64

LIBM: libopenlibm

LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)

```

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [January 22, 2019, 8:51pm UTC](https://discourse.julialang.org/t/fatal-error-when-jl-file-included/19946/2 "2019-01-22T20:51:46Z")

</div>

> [@dan123](#):
>
> function convert(s1, x::Int64)

This should be `function convert(::Type{s1}, x::Int64)` — you want the first argument to be [the _type_](https://docs.julialang.org/en/v1/manual/types/#man-singleton-types-1) `s1` not just _named_ `s1`.

By defining `convert(s1, x::Int64)`, where the type of the first argument is not specified, you are potentially redefining how Julia converts _any_ `Int64` value to _any_ type, which can break the core libraries. This is also known as [type piracy](https://docs.julialang.org/en/v1/manual/style-guide/index.html#Avoid-type-piracy-1). (The analogue in Python would be something like monkey-patching the standard libraries.)

See also [this section](https://docs.julialang.org/en/v1/manual/conversion-and-promotion/#Defining-New-Conversions-1) of the manual.

---

<div class="post-metadata">

### Author: ![dan123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan123/32/5724_2.png) [@dan123](https://discourse.julialang.org/u/dan123)
#### Post date: [January 22, 2019, 9:14pm UTC](https://discourse.julialang.org/t/fatal-error-when-jl-file-included/19946/3 "2019-01-22T21:14:55Z")

</div>

Thank you!
