google / google/closure-compiler
Nested union types fail equality check
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
``` js
/** @constructor @template T */
function EventType(){}
/**
* @param {string|!EventType} a
* @param {!EventType} b
* @return {boolean}
*/
function compare(a, b) {
return a === b;
}
```
``` js
input0:10: WARNING - condition always evaluates to false
left : (EventType<(boolean|number)>|string)
right: EventType
return a === b;
^
```
The (obviously-incorrect) error only happens if both `|`s are present.
https://closure-compiler-debugger.appspot.com/#input0%3D%252F**%2520%2540constructor%2520%2540template%2520T%2520*%252F%250Afunction%2520EventType()%257B%257D%250A%250A%252F**%250A%2520*%2520%2540param%2520%257Bstring%257C!EventType%253Cboolean%257Cnumber%253E%257D%2520a%250A%2520*%2520%2540param%2520%257B!EventType%253Cboolean%253E%257D%2520b%250A%2520*%2520%2540return%2520%257Bboolean%257D%250A%2520*%252F%250Afunction%2520compare(a%252C%2520b)%2520%257B%250A%2520%2520return%2520a%2520%253D%253D%253D%2520b%253B%250A%257D%250A%26input1%26conformanceConfig%26externs%26refasterjs-template%26includeDefaultExterns%3D1%26CHECK_SYMBOLS%3D1%26CHECK_TYPES%3D1%26CLOSURE_PASS%3D1%26LANG_IN_IS_ES6%3D1%26MISSING_PROPERTIES%3D1%26PRESERVE_TYPE_ANNOTATIONS%3D1%26PRETTY_PRINT%3D1%26TRANSPILE%3D1
Contributor guide
Assessment
This issue has not been assessed yet.