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

Allow constructors to specify value type #69

Open
puzrin opened this issue Jun 14, 2013 · 6 comments
Open

Allow constructors to specify value type #69

puzrin opened this issue Jun 14, 2013 · 6 comments

Comments

@puzrin
Copy link
Member

puzrin commented Jun 14, 2013

#59 (comment)

new Foobar(param) -> Type causes fatal error. I don't know, if such notation is useful, but it costs nothing to implement.

@deepsweet
Copy link

imo it should not throw an error at least because constructor may return
more than just this by default.

i'll use this feature.

On Friday, June 14, 2013, Vitaly Puzrin wrote:

#59 #59 (comment)

new Foobar(param) -> Type causes fatal error. I don't know, if such
notation is useful, but it costs nothing to implement.


Reply to this email directly or view it on GitHubhttps://github.com//issues/69
.

@puzrin
Copy link
Member Author

puzrin commented Jun 14, 2013

ndoc throws error on syntax mismatch. I guess, original pdoc does not allow it too. But, as i said, i don't see principal problems in syntax extention.

/cc @ixti

@ixti
Copy link
Contributor

ixti commented Jun 15, 2013

Constructor can't return anything but this. When you use constructor as a function for a side effect., it's not making constructor return something else. In this case you should simply add two doc-blocks:

/**
 *  new Foobar()
 *
 *  Description of a constructor. In docs it will be explicitly
 *  named as constructor.
 **/

/**
 *  Foobar() -> String
 *
 *  Description of a constructor used as a function.
 **/

@ixti ixti closed this as completed Jun 15, 2013
@deepsweet
Copy link

/**
 *  class Foobar
 *
 *  Class desc.
 **/

...

/**
 *  new Foobar()
 *
 *  Constructor desc.
 **/

/**
 *  Foobar() -> String
 *
 *  Constructor function desc.
 **/
var Foobar = function() {
    ...
    return 'abc';
}

throws name clash: Foobar error.

I'm a little confused :-/ without Foobar() -> String block everything is ok.

@puzrin puzrin reopened this Jun 16, 2013
@ixti
Copy link
Contributor

ixti commented Jun 16, 2013

Ah, right! Indeed. Problem here is that in the way we build AST of doc nodes - we don't separate functions from classes, so for class Foobar AST node will have id Foobar, for it's constructor it will be Foobar.new, for function Foobar AST node id will be Foobar (same as in class) and this causes name conflict.

So either the example above will work either in case if you will avoid class Foobar docblock, or Foobar() -> String. In order to make this work we will need to rework AST building and I don't see obvious solutions here.

Idea of specifying constructor signature as new Foobar() -> String seems awkward to me. new Foobar will always return an object of Foobar prototype, so it looks really strange. Also in documentation it will be called constructor.

Can you please provide an example when constructor used as function for side effects (not just a shorthand syntax of new ProtoName)?

@puzrin
Copy link
Member Author

puzrin commented Jun 19, 2013

Ndoc 3.0.1 allows to assign value for constructor. That's not documented feature, and it's not guaranteed to work in future. But i think, it will not be used widely. So, it will not be a problem to update docs when something changed.

Anyway, we can't spend time now for rewriting AST. If @deepsweet requirement is solved, i would close this ticket.

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