facebook / facebook/hhvm

Hack: No way to write generic function type

Open
#7,451 5 comments 0 reactions 0 assignees View on GitHub
hack
Dominant language
C++
Stars
18.7k
Forks
3.1k
Avg merge
1h 47m
Merged PRs (30d)
2

Description

### HHVM Version

```
HipHop VM 3.15.2 (rel)
Compiler: tags/HHVM-3.15.2-0-g83ac3e5e3f5657be0cf4c55884044f86a7818b90
Repo schema: 608339137764e8365964a1adaa7a27d125b6076f
```
### Standalone code, or other way to reproduce the problem

``` hack
// Interface for things that must be producible from one of many possible inputs
interface Producer<+T> {
public function fromFoo(Foo $foo): T;
public function fromBar(Bar $bar): T;
public function fromXmlString(string $xml): T;
public function fromJsonString(string $json): T;
// ...
}

// The input to a Producer then is a function that accepts a Producer and
// returns a value produced by the Producer.
type producer_input = (function (Producer $p): T);
```
### Expected result

No errors.
### Actual result

Syntax error in definition of `producer_input`: `Expected (`.

![image](https://cloud.githubusercontent.com/assets/1559204/19831004/9f0bc07c-9e4b-11e6-84b9-25a6a32e05d8.png)

This was originally posted on Stack Overflow [here](https://stackoverflow.com/questions/38771190/how-to-write-generic-function-type).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.