# On type annotations

**URL:** <https://discourse.julialang.org/t/on-type-annotations/116305>\
**Category:** New to Julia\
**Created:** [June 27, 2024, 1:13pm UTC](https://discourse.julialang.org/t/on-type-annotations/116305 "2024-06-27T13:13:24Z")\
**Posts on this page:** 1\
**Showing post:** 86

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [July 5, 2024, 9:53am UTC](https://discourse.julialang.org/t/on-type-annotations/116305/86 "2024-07-05T09:53:07Z")

</div>

I’m prototyping a macro to get rid of the conversions here:

> [@A macro for removing calls to Base.convert: @noconvert](https://discourse.julialang.org/t/a-macro-for-removing-calls-to-base-convert-noconvert/116651):
>
> From the prior discussion [on type annotations](https://discourse.julialang.org/t/on-type-annotations/116305) I was wondering what a macro that removed all calls to Base.convert would look like. Here’s my prototype via Cassette.jl: using Cassette Cassette.@context NoConvertCtx; Cassette.overdub(context::NoConvertCtx, ::typeof(Base.convert), \_, x) = x macro noconvert(e) e.head == :function || error("Expression for @noconvert must be a full `function` definition") s = gensym("noconvert") fname = e.args[1].args[1] e2 = deepcopy(e) e2.args[…

```julia-repl
julia> @noconvert function foo(x::Number)
           let x::Int = x
               x
           end
       end
foo (generic function with 2 methods)

julia> foo(3)
3

julia> foo(3.0)
ERROR: TypeError: in typeassert, expected Int64, got a value of type Float64

julia> foo(3.5)
ERROR: TypeError: in typeassert, expected Int64, got a value of type Float64

```

The code generation looks pretty clean:

```julia-repl
julia> @code_llvm foo(3)
; @ none within `foo`
define i64 @julia_foo_1572(i64 signext %0) #0 {
top:
  ret i64 %0
}

julia> @code_llvm foo(3.0)
; @ none within `foo`
; Function Attrs: noreturn
define void @julia_foo_1574(double %0) #0 {
top:
  call void @j_overdub_1576(double %0) #6
  unreachable
}

```

---

_[View the full topic](https://discourse.julialang.org/t/on-type-annotations/116305)._
