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

TypeHint for setter #12

Open
Naddiseo opened this issue Jun 8, 2015 · 5 comments · May be fixed by #37
Open

TypeHint for setter #12

Naddiseo opened this issue Jun 8, 2015 · 5 comments · May be fixed by #37

Comments

@Naddiseo
Copy link
Collaborator

Naddiseo commented Jun 8, 2015

Probably doesn't need an explicit TypeHint, but semantics could state that settings are implicitly void.

Naddiseo added a commit to Naddiseo/es-type-hinting that referenced this issue Jun 11, 2015
Added yield parameter and option to `TypeHint`s

Added typehint to `set`s so that the syntax is consistent, but added a TODO about static analysis.

This PR should finish up the syntax, closes lukescott#1, and lukescott#12

(refs lukescott#19)
@Naddiseo
Copy link
Collaborator Author

I added a TODO in the spec for the semantics behind this. Let's get some feedback from other spec writers regarding if it's needed.

Naddiseo pushed a commit that referenced this issue Jun 17, 2015
Disallow void generators.
Ensure setters are void. (closes #12)
Added `any` as a base type. (closes #14)
@Naddiseo Naddiseo linked a pull request Jun 17, 2015 that will close this issue
@lukescott
Copy link
Owner

"Ensure setters are void" - does that mean you have to do:

class Foo {
  set value() void {

  }
}

If that's the case, shouldn't TypeHint be disallowed as a return on a setter? That would be more compatible with existing code.

Also, shouldn't a getter and setter be required to use the same TypeHint? As in:

This would be correct:

class Foo {
  get value() string {
    return this._value;
  }
  set value(v string) {
    this._value = v;
  }
}

But this would be invalid:

class Foo {
  get value() string {
    return this._value;
  }
  set value(v number) {
    this._value = v;
  }
}

I know this sort of type checking territory, but I ask because both methods share the same descriptor.

@Naddiseo
Copy link
Collaborator Author

The syntax allows empty, but if it's not empty, then it ensures that the return type is void. It's because I used parametized grammar, so it looks strange.

@lukescott
Copy link
Owner

Should void even be allowed on setter? Is the set keyword enough?

@Naddiseo
Copy link
Collaborator Author

set PropertyName[?Yield] ( PropertySetParameterList ) TypeHint[?Yield]opt { FunctionBody }

TypeHint is optional, so that generates two syntax rules, one with the TypeHint, and one without. The semantic checking only applies when it matches the line with the TypeHint.

Should void even be allowed on setter? Is the set keyword enough?

I added it in for symmetry. I think it would be surprising if it were forbidden.

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

Successfully merging a pull request may close this issue.

2 participants