Skip to content

default inner constructors should accept any arguments #4026

Closed

Description

Once upon a time if you did this, it would work:

type Foo
  x::Float64
end

julia> Foo(1)
Foo(1.0)

It was pretty convenient. However, back then convert was quite aggressive and this also worked:

type Bar
  y::Int
end

julia> Bar(1.5)
Bar(2) # or Bar(1) depending on when you tried it

This was deemed dangerous and confusing, so default constructors were changed to not call convert for you. Today, however, convert is far more conservative and convert(Int,1.5) fails with an InexactError. Therefore, I propose that we reinstate the old convenient behavior of calling convert automatically in inner constructors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions