# Weird datatype behaviour

**URL:** <https://discourse.julialang.org/t/weird-datatype-behaviour/17879>\
**Category:** General Usage\
**Created:** [November 22, 2018, 7:16pm UTC](https://discourse.julialang.org/t/weird-datatype-behaviour/17879 "2018-11-22T19:16:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hackguy](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@hackguy](https://discourse.julialang.org/u/hackguy)\
**Post date:** [November 22, 2018, 7:16pm UTC](https://discourse.julialang.org/t/weird-datatype-behaviour/17879/1 "2018-11-22T19:16:23Z")

</div>

I’m trying to create a 24-bit datatype for a [SIC/XE assembly](https://en.wikipedia.org/wiki/Simplified_Instructional_Computer) simulator. So far I have this code:

```julia
import Core.Intrinsics

# defining a primitive 24-bit integer type for integer registers
primitive type SICInt 24 end

# other signed types -> SICInt
SICInt(x::Int) = Core.Intrinsics.trunc_int(SICInt, x)

# SICInt -> other signed types
Int32(x::SICInt) = Core.Intrinsics.sext_int(Int32, x)
Int64(x::SICInt) = Core.Intrinsics.sext_int(Int64, x)
Int(x::SICInt) = Core.Intrinsics.sext_int(Int, x)

# printing help
Base.show(io::IO, x::SICInt) = print(io, Int(x))

# Math operations
# TODO

# machine data structure
mutable struct Machine

    # registers
    A::SICInt
    B::SICInt
    X::SICInt
    L::SICInt
    S::SICInt
    T::SICInt
    F::Float64 # TODO
end

```

saved in a file called `machine.jl`.  
Weird behaviour happens when I try to load the code into REPL:  
 ![](https://global.discourse-cdn.com/julialang/original/3X/1/9/19ffe4dd67787612f1cc931689c61ca3463f97b3.png)  
see: 2 became of type Core.Int64 instead of Int64.  
Strangely, this doesn’t happen if I call `typeof(2)` _before_ the include statement:  
 ![](https://global.discourse-cdn.com/julialang/original/3X/1/e/1e53316454d236b4cbee924497d5c41bc568e215.png)  
Does anyone have any idea what could be going wrong here or how could I fix this?  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [November 23, 2018, 12:43am UTC](https://discourse.julialang.org/t/weird-datatype-behaviour/17879/2 "2018-11-23T00:43:31Z")

</div>

First things first, `Int64` and `Core.Int64` are the same type, so nothing has actually changed type:

```julia
julia> Int64 === Core.Int64
true

```

However, you’re defining:

```julia
Int64(x::SICInt) = Core.Intrinsics.sext_int(Int64, x)

```

but you never did `import Core: Int64`, so your definition is actually creating a _totally new function_ that just happens to have the name `Int64`.

The last part is why the printing of `Int64` changes. I don’t totally understand the code that controls it (you can find it here: [julia/show.jl at 038d8665afd2eeeaca81ba5ebd3da1ece40e69bc · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/blob/038d8665afd2eeeaca81ba5ebd3da1ece40e69bc/base/show.jl#L449) ), but it seems that Julia tries to abbreviate `Core.Int64` to `Int64` since `Int64` is defined in the `Main` module and is identical to `Core.Int64`. After your code is imported, there’s a brand new function called `Int64`, which has nothing to do with `Core.Int64`, so Julia has to print the entire `Core.Int64` when showing the type name.

Now there’s a further question of why that behavior depends on the order of operations, which I admit I don’t totally understand.

So, to summarize:

- Nothing has changed type, just the way some types are printed was changed to avoid conflicting with your `Int64` and other definitions…
- … but the real problem is that you presumably meant to do `Core.Int64(...) = ...` or `import Core: Int64; Int64(...) = ...` . I would recommend the former, as it’s more obvious to future readers of the code what is going on.

---

<div class="post-metadata">

**Author:** ![hackguy](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@hackguy](https://discourse.julialang.org/u/hackguy)\
**Post date:** [November 24, 2018, 2:25pm UTC](https://discourse.julialang.org/t/weird-datatype-behaviour/17879/3 "2018-11-24T14:25:50Z")

</div>

Thank you, adding the line

```julia
import Core: Int64, Int32

```

solved the problem.
