# Composite Type Registering as Any with @code\_warntype

**URL:** <https://discourse.julialang.org/t/composite-type-registering-as-any-with-code-warntype/5196>\
**Category:** General Usage\
**Created:** [August 3, 2017, 1:00am UTC](https://discourse.julialang.org/t/composite-type-registering-as-any-with-code-warntype/5196 "2017-08-03T01:00:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaela\_Martin](https://avatars.discourse-cdn.com/v4/letter/k/c77e96/32.png) [@Kaela\_Martin](https://discourse.julialang.org/u/Kaela_Martin)\
**Post date:** [August 3, 2017, 1:00am UTC](https://discourse.julialang.org/t/composite-type-registering-as-any-with-code-warntype/5196/1 "2017-08-03T01:00:48Z")

</div>

When I pass a composite type into a function, it doesn’t seem to know the element type even if it is explicitly defined. Should Julia be able to infer the type?

```julia
type TEST
  Notes::AbstractArray{Float64}
  Time::Float64
end

```

```julia
function foo(test::TEST)
  tempvar1 = test.Notes[1]
  tempvar2 = tempvar1*2. + test.Time
end

```

```julia
Variables:
  #self#::#foo
  test::TEST
  tempvar1::Any
  tempvar2::Any

Body:
  begin
      tempvar1::Any = (Main.getindex)((Core.getfield)(test::TEST, :Notes)::AbstractArray{Float64,N} where N, 1)::Any # line 3:
      SSAValue(0) = ((tempvar1::Any * 2.0)::Any + (Core.getfield)(test::TEST, :Time)::Float64)::Any
      return SSAValue(0)
  end::Any

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 3, 2017, 1:08am UTC](https://discourse.julialang.org/t/composite-type-registering-as-any-with-code-warntype/5196/2 "2017-08-03T01:08:58Z")

</div>

No, `getindex` on `AbstractArray{Float64}` can return anything.

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [August 3, 2017, 2:15am UTC](https://discourse.julialang.org/t/composite-type-registering-as-any-with-code-warntype/5196/3 "2017-08-03T02:15:18Z")

</div>

Abstract fields in composite types let you down in so many ways.

Compare with say:

```julia
type TEST2{T<:AbstractArray{Float64}}
    Notes::T
    Time::Float64
end

```

---

<div class="post-metadata">

**Author:** ![Kaela\_Martin](https://avatars.discourse-cdn.com/v4/letter/k/c77e96/32.png) [@Kaela\_Martin](https://discourse.julialang.org/u/Kaela_Martin)\
**Post date:** [August 3, 2017, 2:55pm UTC](https://discourse.julialang.org/t/composite-type-registering-as-any-with-code-warntype/5196/4 "2017-08-03T14:55:37Z")

</div>

Thanks for the suggestion!

type TEST2 worked!

```julia
Variables:
  #self#::#foo
  test::TEST2{Array{Float64,1}}
  tempvar1::Float64
  tempvar2::Float64

```
