facebook / facebook/hhvm

[Bug] incorrect invalid return type error using shapes and union type

Open
#8,789 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request hack
Dominant language
C++
Stars
18.7k
Forks
3.1k
Avg merge
1h 47m
Merged PRs (30d)
2

Description

**Describe the bug**

With the union type feature enabled, hh_client doesn't seem to understand the union between shapes that contain optional extra fileds.

**Standalone code, or other way to reproduce the problem**
```hack
interface C {
public function with(): C<(T & Ts)>;
}

function bar(
C shape('a' => int), ...)> $config,
): C shape('a' => int), 'bar' => int, ...)> {
return $config->with int,
...
)>();
}
```

**Expected behavior**

No errors.

**Actual behavior**

```
Typing[4110] Invalid return typeHack(4110)
playground.hack(20, 6): Expected shape('bar' => int, 'hello' => shape('a' => int), ...)
playground.hack(20, 6): This type argument to Nuxed\Playground\C must match exactly (it is invariant)
playground.hack(15, 39): But got (shape('hello' => shape('a' => int), ...) & shape('bar' => int, ...))
```

**Environment**

```
❯ hhvm --version
HipHop VM 4.85.0 (rel)
Compiler: 1606769234_148788027
Repo schema: d1ae8e21bf3419a65f12a010527485564e719d07
❯ hh_client --version
hackc-fd31045126d9e76368e3fa73817029cf8e5da3f3-4.85.0
❯ hh_server --version
hackc-fd31045126d9e76368e3fa73817029cf8e5da3f3-4.85.0
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the standalone Hack example with union types using hh_client and compare the reported invalid return type with the expected shape type. Use the diagnostics from playground.hack as the starting reference, then verify the behavior against the listed HHVM, hh_client, and hh_server versions. Done means the example produces no invalid return type error.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.