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

default inner constructors should accept any arguments #4026

Closed
StefanKarpinski opened this issue Aug 12, 2013 · 4 comments
Closed

default inner constructors should accept any arguments #4026

StefanKarpinski opened this issue Aug 12, 2013 · 4 comments
Assignees
Milestone

Comments

@StefanKarpinski
Copy link
Member

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.

@toivoh
Copy link
Contributor

toivoh commented Aug 12, 2013

+1

@JeffBezanson
Copy link
Member

I anticipate mild outrage over how easy this is to fix.

@StefanKarpinski
Copy link
Member Author

I am mildly outraged :-P

@StefanKarpinski
Copy link
Member Author

This is really, really nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants