facebookarchive / hack-langspec

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

Add grammar and description for "where" clauses #100

Open ericlippert opened 7 years ago

ericlippert commented 7 years ago

Hack supports an optional "where" clause on a function definition; it comes last (after the return type, before the body.)

The grammar is

  where-clause:
    where constraint-list
  constraint-list:
    constraint
    constraint-list , constraint
  constraint:
    type-specifier  constraint-operator  type-specifier
  constraint-operator:
    =
    as
    super

Note that a trailing comma is not accepted in a constraint list.

The grammar should be amended to include these productions, and the description of a function header should describe the semantics of the clause.