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

when defineing an optional arg it should define that field to be the same type as the default value #2

Closed
jkroso opened this issue Nov 2, 2016 · 5 comments

Comments

@jkroso
Copy link

jkroso commented Nov 2, 2016

Eg:

macroexpand(:(@qtype A(b=1)))

Becomes

quote
  type A
    b::Int
  end
  A()=A(1)
end
@cstjean
Copy link
Owner

cstjean commented Nov 2, 2016

That was a conscious decision, because it allows for @qtype A(b::Float64=1), whereas if we asserted it in the constructor, that would be an error. Since normal arguments are converted, it seemed reasonable that the defaults be converted too.

@jkroso
Copy link
Author

jkroso commented Nov 6, 2016

I'm not sure I follow. But I agree that @qtype A(b::Float64=1) should not get transformed into the same thing that I suggested @qtype A(b=1) get transformed into

@cstjean
Copy link
Owner

cstjean commented Nov 6, 2016

Oh! I'm sorry; I misread your suggestion. Ignore what I said above.

That's an interesting proposal, but it would be unexpected behaviour for most users. Consider @qtype Window(color, button=nothing), where nothing is a default value. It would translate into

quote
   type Window
      color
      button::Void
   end
end

which is obviously not useful.

@jkroso
Copy link
Author

jkroso commented Nov 6, 2016

And that brings up another case @qtype Window(color, button::Nullable). Which should get transformed to:

type Window
  color::Any
  Button::Nullable
end
Window(color)=Window(color,nothing)

ie. Nullable's should be be treated as optional arguments

@cstjean
Copy link
Owner

cstjean commented Nov 6, 2016

See #1

@cstjean cstjean closed this as completed Nov 6, 2016
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

2 participants