# Keyword arguments of 32-bit type don't work

**URL:** https://discourse.julialang.org/t/keyword-arguments-of-32-bit-type-dont-work/135311
**Category:** General Usage
**Tags:** error, keyword-arguments
**Created:** [January 28, 2026, 7:27pm UTC](https://discourse.julialang.org/t/keyword-arguments-of-32-bit-type-dont-work/135311 "2026-01-28T19:27:40Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)
#### Post date: [January 28, 2026, 7:27pm UTC](https://discourse.julialang.org/t/keyword-arguments-of-32-bit-type-dont-work/135311/1 "2026-01-28T19:27:40Z")

</div>

Why **32bit** keyword argument [functions](https://docs.julialang.org/en/v1/manual/functions/#Keyword-Arguments) give error _(Int32 also)_ ?

```julia-auto
julia> x = 2
2

julia> function sixty_four(x; y::Float64=0.5)
               x+y
       end
sixty_four (generic function with 1 method)

julia> function thirty_two(x; y::Float32=0.5)
               x+y
       end
thirty_two (generic function with 1 method)

julia> sixty_four(x)
2.5

julia> thirty_two(x)
ERROR: MethodError: no method matching var"#thirty_two#2"(::Float64, ::typeof(thirty_two), ::Int64)
The function `#thirty_two#2` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  var"#thirty_two#2"(::Float32, ::typeof(thirty_two), ::Any)
   @ Main REPL[3]:1

Stacktrace:
 [1] thirty_two(x::Int64)
   @ Main ./REPL[3]:1
 [2] top-level scope
   @ REPL[5]:1

```

---

<div class="post-metadata">

### Author: ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)
#### Post date: [January 28, 2026, 7:31pm UTC](https://discourse.julialang.org/t/keyword-arguments-of-32-bit-type-dont-work/135311/2 "2026-01-28T19:31:52Z")

</div>

`0.5` is not a `Float32`. try `0.5f0`

---

<div class="post-metadata">

### Author: ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)
#### Post date: [January 28, 2026, 7:35pm UTC](https://discourse.julialang.org/t/keyword-arguments-of-32-bit-type-dont-work/135311/3 "2026-01-28T19:35:10Z")

</div>

Ok, Thanks so i should first convert it to `Float32`.

```julia-auto
julia> isa(0.5, Float32)
false

julia> isa(Float32(0.5), Float32)
true

```

This updated version `thirty_two(x; y=Float32(0.5))` is also type stable. 😃

```julia-auto
julia> x = 2
2

julia> function sixty_four(x; y::Float64=0.5)
               x+y
       end
sixty_four (generic function with 1 method)

julia> function thirty_two(x; y=Float32(0.5))
               x+y
       end
thirty_two (generic function with 1 method)

julia> sixty_four(x)
2.5

julia> thirty_two(x)
2.5f0

julia> @code_warntype thirty_two(x)
MethodInstance for thirty_two(::Int64)
  from thirty_two(x; y) @ Main REPL[9]:1
Arguments
  #self#::Core.Const(Main.thirty_two)
  x::Int64
Body::Float32
1 ─ %1 = Main.:(var"#thirty_two#52")::Core.Const(Main.var"#thirty_two#52")
│ %2 = Main.Float32::Core.Const(Float32)
│ %3 = (%2)(0.5)::Core.Const(0.5f0)
│ %4 = (%1)(%3, #self#, x)::Float32
└── return %4

```

---

<div class="post-metadata">

### Author: ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)
#### Post date: [January 28, 2026, 7:36pm UTC](https://discourse.julialang.org/t/keyword-arguments-of-32-bit-type-dont-work/135311/4 "2026-01-28T19:36:59Z")

</div>

This also applies to positional arguments:

```julia-repl
julia> f(x::Int32 = 1) = x
f (generic function with 2 methods)

julia> methods(f)
# 2 methods for generic function "f" from Main:
 [1] f(x::Int32)
     @ REPL[1]:1
 [2] f()
     @ REPL[1]:1

julia> @code_lowered f()
CodeInfo(
1 ─ %1 = dynamic (#self#)(1)
└── return %1
)

```

I.e. we here create two methods. The nullary version just calls `f(1)`, which is undefined as there is no `f(::Int64)`.

---

<div class="post-metadata">

### Author: ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)
#### Post date: [January 28, 2026, 7:56pm UTC](https://discourse.julialang.org/t/keyword-arguments-of-32-bit-type-dont-work/135311/5 "2026-01-28T19:56:02Z")

</div>

This means that types are not checked during function definition. Types are inferred when the function is called or run on some value. 😃

> [@eldee](#):
>
> `1 ─ %1 = dynamic (#self#)(1)`

What does `dynamic` refers to here _( i.e. type of variable `%1` is not known or is dynamic)_?

---

<div class="post-metadata">

### Author: ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)
#### Post date: [January 28, 2026, 9:00pm UTC](https://discourse.julialang.org/t/keyword-arguments-of-32-bit-type-dont-work/135311/6 "2026-01-28T21:00:10Z")

</div>

You can do:

```julia-auto
generic(x; y=0.5f0) = x+y

If you must restrict to floats:
generic(x; y::AbstractFloat=0.5f0) = x+y

or:

generic(x; y::Real=0.5f0) = x+y

```

These all take Float64 (and e.g. Float16, and Integers for the first), and if x is Float64 y the default arg gets converted to Float64.

---

<div class="post-metadata">

### Author: ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)
#### Post date: [January 29, 2026, 5:37pm UTC](https://discourse.julialang.org/t/keyword-arguments-of-32-bit-type-dont-work/135311/7 "2026-01-29T17:37:28Z")

</div>

> [@raman\_kumar](#):
>
> This means that types are not checked during function definition.

Yeah, this seems right. In principle this gives you the liberty to do something like

```julia-auto
f(x::Int32 = 1) = x + 1
f(x::Int64) = x - 1

```

```julia-repl
julia> f()
0

```

but there’s really no point as you could also just write the much clearer `f(x::Int64 = 1) = x - 1`.

> [@raman\_kumar](#):
>
> Types are inferred when the function is called or run on some value. 😃

Depending on how you interpret this, this might also be correct, but let me point out that already during compilation (so not only at runtime) Julia will notice our original `f` (or `thirty_two`) does not make sense. For example, we already get

```julia-repl
julia> f(x::Int32 = 1) = x
f (generic function with 2 methods)

julia> @code_typed f()
CodeInfo(
1 ─ builtin Core.throw_methoderror(#self#, 1)::Union{}
└── unreachable
) => Union{}

```

> [@raman\_kumar](#):
>
> What does `dynamic` refers to here _( i.e. type of variable `%1` is not known or is dynamic)_?

`dynamic` seems to be new as of Julia v1.12. I don’t think we should worry about it, as every function call seems to be dynamic according to `@code_lowered`. Presumably this is typically no longer relevant further along the lowering/compilation pipeline, but I’m certainly no expert, so hopefully someone more knowledgeable can chime in.
