google / google/closure-compiler

Inline return types aren't checked when passed as a parameter

Open
#1,386 0 comments 0 reactions 0 assignees View on GitHub
Types
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

``` js
/** @param {function({a: number}): (string)} fn */
function run(fn) {}

run(function /** number */ foo(x) { return 'a'; });
run(function /** number */ foo(x) { return null; });
(function /** number */ foo(x) { return null; });
```

When passed to `run()`, the function completely ignores the `/** number */` annotation.

The first call gives no warnings, even though neither the function nor its return value match their requirements.
The second call warns against `string`, not `number`.
The third call, which is not passed to a function, works fine.

https://closure-compiler-debugger.appspot.com/#input0%3D%252F**%2520%2540param%2520%257Bfunction(%257Ba%253A%2520number%257D)%253A%2520(string)%257D%2520fn%2520*%252F%250Afunction%2520run(fn)%2520%257B%257D%250A%250Arun(function%2520%252F**%2520number%2520*%252F%2520foo(x)%2520%257B%2520return%2520'a'%253B%2520%257D)%253B%250Arun(function%2520%252F**%2520number%2520*%252F%2520foo(x)%2520%257B%2520return%2520null%253B%2520%257D)%253B%250A(function%2520%252F**%2520number%2520*%252F%2520foo(x)%2520%257B%2520return%2520null%253B%2520%257D)%253B%250A%250A%26input1%26conformanceConfig%26externs%26refasterjs-template%26includeDefaultExterns%3D1%26CHECK_SYMBOLS%3D1%26CHECK_TYPES%3D1%26MISSING_PROPERTIES%3D1

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.