facebookarchive / hack-langspec

The official Hack Language specification.
http://hacklang.org
Other
172 stars 48 forks source link

Problems with type constraint specification #83

Open ericlippert opened 7 years ago

ericlippert commented 7 years ago

First off, a typo.

In the chapter on types we have:

generic-type-parameter-variance-opt generic-type-parameter-name type-constraint-opt

And then later

The type-specifier in generic-type-constraint must not be this or ?this.

The latter is correct. The former must be generic-type-constraint-opt.

Second, a type constraint is specified as

as type-specifier

but in a generic type parameter declaration we also allow:

super type-specifier

I've entered another issue to track the fact that "super" is not listed as a keyword.

However, we use type-constraint as a production in more places than just generic type parameters, and it is not yet clear to me which ones allow "super" and which ones allow only "as". I'll do some looking into that. But for now what we should probably do is have two productions:

generic-type-parameter-constraint: as type-specifier super type-specifier

type-parameter-constraint: as type-specifier

Third, we now permit more than one type constraint on a generic type parameter. So the grammar should be changed to indicate that this is a list of zero or more generic-type-constraints. (Note that the list is NOT comma separated for obvious reasons!)