Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immutable type incorrectly created #8010

Closed
tknopp opened this issue Aug 15, 2014 · 1 comment
Closed

Immutable type incorrectly created #8010

tknopp opened this issue Aug 15, 2014 · 1 comment
Assignees
Labels
kind:bug Indicates an unexpected problem or unintended behavior

Comments

@tknopp
Copy link
Contributor

tknopp commented Aug 15, 2014

This is from https://groups.google.com/forum/#!topic/julia-users/LIXG4TjUpDI
and it might not be a Julia bug.

The issue is in ImmutableArrays.jl where the convert function is able to create a type other than the passed one. Here is a reduced test case:

immutable Vec2{T}
    x::T
    y::T
end

Vec2(a::AbstractVector) = Vec2(ntuple(2,x->a[x])...)

import Base.convert
convert{T}(::Type{Vec2{T}},x::AbstractVector) = Vec2(x)   

immutable MyType
     m::Vec2{Float32}
end

println(MyType([3.0;4.0]))

This pasted in a REPL prints

MyType(Vec2{Float32}(0.0f0,2.125f0))

Might it be able to detect when MyType is constructed the it got passed a Vec2{Float64}?

@JeffBezanson
Copy link
Sponsor Member

Seems it gets checked if MyType is mutable, and not if it is immutable. That seems like a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants