# Trouble with types when porting old Compose.jl code to v0.6

**URL:** <https://discourse.julialang.org/t/trouble-with-types-when-porting-old-compose-jl-code-to-v0-6/2263>\
**Category:** Internals & Design\
**Created:** [February 24, 2017, 1:45am UTC](https://discourse.julialang.org/t/trouble-with-types-when-porting-old-compose-jl-code-to-v0-6/2263 "2017-02-24T01:45:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlnagy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlnagy/32/5815_2.png) [@tlnagy](https://discourse.julialang.org/u/tlnagy)\
**Post date:** [February 24, 2017, 1:45am UTC](https://discourse.julialang.org/t/trouble-with-types-when-porting-old-compose-jl-code-to-v0-6/2263/1 "2017-02-24T01:45:40Z")

</div>

I’m in the process of updating `Compose.jl` to work with Julia 0.6 and I got a MethodError thrown when accessing the new constructor via a typealias: (this was originally posted over here: [Advice needed for updating to new stricter parameterized type system + typealiasing · Issue #20774 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/20774)

## Changes made on my part

I added `@compat` and `{P}` and `where {P}` do the following object definition:

```julia
immutable Form{P <: FormPrimitive} <: ComposeNode
    primitives::Vector{P}
    tag::Symbol

    @compat function Form{P}(prim, tag::Symbol=empty_tag) where {P <: FormPrimitive}
        new(prim, tag)
    end
end

```

and updated a typealias:

old:

```julia-auto
immutable SimplePolygonPrimitive{P <: Vec} <: FormPrimitive
    points::Vector{P}
end

typealias SimplePolygon{P<:SimplePolygonPrimitive} Form{P}

typealias Polygon SimplePolygon
typealias PolygonPrimitive SimplePolygonPrimitive

```

new:

```julia-auto
immutable SimplePolygonPrimitive{P <: Vec} <: FormPrimitive
    points::Vector{P}
end

const SimplePolygon{P<:SimplePolygonPrimitive} = Form{P}

const Polygon = SimplePolygon
const PolygonPrimitive = SimplePolygonPrimitive

```

## Differences in behavior

OLD:

```julia
julia> using Compose

julia> x = [Compose.PolygonPrimitive(Tuple{Measure, Measure}[(Compose.x_measure(point[1]), Compose.y_measure(point[2]))
                                  for point in [(0.1, 0.2), (0.3, 0.4), (0.5, 0.6)]])]
1-element Array{Compose.SimplePolygonPrimitive{Tuple{Measures.Measure,Measures.Measure}},1}:
 Compose.SimplePolygonPrimitive{Tuple{Measures.Measure,Measures.Measure}}(Tuple{Measures.Measure,Measures.Measure}[(0.1cx,0.2cy),(0.3cx,0.4cy),(0.5cx,0.6cy)])

julia> Compose.Form(x, Compose.empty_tag)
Compose.Form{Compose.SimplePolygonPrimitive{Tuple{Measures.Measure,Measures.Measure}}}(Compose.SimplePolygonPrimitive{Tuple{Measures.Measure,Measures.Measure}}[Compose.SimplePolygonPrimitive{Tuple{Measures.Measure,Measures.Measure}}(Tuple{Measures.Measure,Measures.Measure}[(0.1cx,0.2cy),(0.3cx,0.4cy),(0.5cx,0.6cy)])],Symbol(""))

julia> Compose.Polygon(x, Compose.empty_tag)
Compose.Form{Compose.SimplePolygonPrimitive{Tuple{Measures.Measure,Measures.Measure}}}(Compose.SimplePolygonPrimitive{Tuple{Measures.Measure,Measures.Measure}}[Compose.SimplePolygonPrimitive{Tuple{Measures.Measure,Measures.Measure}}(Tuple{Measures.Measure,Measures.Measure}[(0.1cx,0.2cy),(0.3cx,0.4cy),(0.5cx,0.6cy)])],Symbol(""))

```

NEW:

```julia
julia> using Compose

julia> x = [Compose.PolygonPrimitive(Tuple{Measure, Measure}[(Compose.x_measure(point[1]), Compose.y_measure(point[2]))
                                  for point in [(0.1, 0.2), (0.3, 0.4), (0.5, 0.6)]])]
1-element Array{Compose.SimplePolygonPrimitive{Tuple{Measures.Measure,Measures.Measure}},1}:
 Compose.SimplePolygonPrimitive{Tuple{Measures.Measure,Measures.Measure}}(Tuple{Measures.Measure,Measures.Measure}[(0.1cx, 0.2cy), (0.3cx, 0.4cy), (0.5cx, 0.6cy)])

julia> Compose.Form(x, Compose.empty_tag)
Compose.Form{Compose.SimplePolygonPrimitive{Tuple{Measures.Measure,Measures.Measure}}}(Compose.SimplePolygonPrimitive{Tuple{Measures.Measure,Measures.Measure}}[Compose.SimplePolygonPrimitive{Tuple{Measures.Measure,Measures.Measure}}(Tuple{Measures.Measure,Measures.Measure}[(0.1cx, 0.2cy), (0.3cx, 0.4cy), (0.5cx, 0.6cy)])], Symbol(""))

julia> Compose.Polygon(x, Compose.empty_tag)
ERROR: MethodError: no method matching Compose.Form{P} where P<:Compose.SimplePolygonPrimitive(::Array{Compose.SimplePolygonPrimitive{Tuple{Measures.Measure,Measures.Measure}},1}, ::Symbol)
Closest candidates are:
  Compose.Form{P} where P<:Compose.SimplePolygonPrimitive(::Any) where T at sysimg.jl:24

```

Do you all have any suggestions on what I’m doing wrong? I’m not sure why this code broke on v0.5.

---

<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:** [February 24, 2017, 2:06am UTC](https://discourse.julialang.org/t/trouble-with-types-when-porting-old-compose-jl-code-to-v0-6/2263/2 "2017-02-24T02:06:04Z")

</div>

> [@tlnagy](#):
>
> @compat function Form{P}(prim, tag::Symbol=empty\_tag) where {P \<: FormPrimitive}

For 0.5, I don’t think `@compat` can handle this.

For the constructor method error, it’s a bug on 0.5 if it doesn’t rase an error there.

---

<div class="post-metadata">

**Author:** ![tlnagy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlnagy/32/5815_2.png) [@tlnagy](https://discourse.julialang.org/u/tlnagy)\
**Post date:** [February 24, 2017, 2:11am UTC](https://discourse.julialang.org/t/trouble-with-types-when-porting-old-compose-jl-code-to-v0-6/2263/3 "2017-02-24T02:11:27Z")

</div>

> For 0.5, I don’t think @compat can handle this.

Then what’s the recommended way of preserving backwards compatability?

> For the constructor method error, it’s a bug on 0.5 if it doesn’t rase an error there.

This is 3 year old code and has worked on every previous version of Julia. I didn’t write it and I don’t fully understand how it works.

---

<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:** [February 24, 2017, 2:27am UTC](https://discourse.julialang.org/t/trouble-with-types-when-porting-old-compose-jl-code-to-v0-6/2263/4 "2017-02-24T02:27:09Z")

</div>

> [@tlnagy](#):
>
> Then what’s the recommended way of preserving backwards compatability?

> <https://github.com/JuliaCollections/DataStructures.jl/pull/268/files#diff-78071e0e2a3c314cff6bd5583a983f9cL32>

> [@tlnagy](#):
>
> This is 3 year old code and has worked on every previous version of Julia. I didn’t write it and I don’t fully understand how it works.

I mean it’s a base julia bug that it worked on 0.5, it was never supposed to work. You don’t need to understand why it worked to fix it (though you do need to understand how it is supposed to behave/what is supposed to work). Jeff have already clearly pointed out the correct way to make it work, have you tried it already?

---

<div class="post-metadata">

**Author:** ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)\
**Post date:** [April 6, 2017, 12:24pm UTC](https://discourse.julialang.org/t/trouble-with-types-when-porting-old-compose-jl-code-to-v0-6/2263/5 "2017-04-06T12:24:20Z")

</div>

see [https://github.com/JuliaLang/Compat.jl/issues/332](https://github.com/JuliaLang/Compat.jl/issues/332) for the otherwise insufficiently documented way to make inner constructors work for both julia 0.5 and 0.6
