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

Should method definitions in records fail at parse time or runtime? #88

Closed
rickbutton opened this issue Dec 6, 2019 · 7 comments · Fixed by #89
Closed

Should method definitions in records fail at parse time or runtime? #88

rickbutton opened this issue Dec 6, 2019 · 7 comments · Fixed by #89

Comments

@rickbutton
Copy link
Member

i.e.

const x = #{
    method() {
        return 123;
    }
};

should this fail to parse, or should this fail with an error at runtime because function objects can't be stored in Records?

@ljharb
Copy link
Member

ljharb commented Dec 6, 2019

Seems like it should fail to parse? However,

const x = #{
    method: () => {
        return 123;
    }
};

would presumably have to fail at runtime, so maybe it's simpler to make them all be runtime checks?

@rickbutton
Copy link
Member Author

I agree that it would be simpler (since record syntax would just become "object literals but with different start/end tokens"), but it would be odd to allow record syntax to express a record that will always fail.

@ljharb
Copy link
Member

ljharb commented Dec 6, 2019

#{ key: (function () { throw 'always fails' }()) } too, since the RHS is an expression - so i'm not sure if it's all that odd.

@rickbutton
Copy link
Member Author

Good point. I think I've been converted to thinking it should be a runtime error. I'll leave the issue open though, I'm curious if anyone else has opinions.

@littledan
Copy link
Member

I'm happy with this conclusion as a starting point, but I'd also be open to reconsidering as we get more concrete with the spec text (which is often somehow helpful in making all of this very clear).

@ljharb
Copy link
Member

ljharb commented Dec 7, 2019

Either option seems reasonable to me; I personally prefer maximizing parse time errors, but committee precedent in the past has seemed to be that when some kinds of errors need to be runtime, they should all be deferred to runtime.

@acutmore
Copy link
Collaborator

Just a note for future readers. Since this was closed the spec has since been written to make method-syntax in a record a syntax-error.

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.

5 participants