google / google/closure-compiler
generics not checked depending on definition position in file
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
I have a problem where the compiler is allowing things it shouldn't.
I have asynchronous API calls that are used by passing them a callback function. The callbacks expect a Response object as their parameter, and the Response object has a template. So the API call getNumber expects a `function(Response)` callback, getString expects a `function(Response)` etc.
The problem is that if I pass a `function(Response)` as a callback to getNumber, the compiler doesn't show a warning.
I've tracked this down to the order that things are defined in the file - if the order is incorrect then the compiler appears to act as if Response does not have a template defined and so allows things it shouldn't.
I have created a [gist](https://gist.github.com/ghosttie/b28b4f5a965d952fc8cb) that reproduces the problem - if you compile that file as is, there are no compiler warnings, but if you move the definitions of GetNumberCallback and GetStringCallback to the bottom of the file the compiler shows the expected warnings.
This happens when compiling in advanced mode.
Contributor guide
Assessment
This issue has not been assessed yet.