google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.42k stars 1.15k forks source link

Type created using @typedef in inner scope is not recognized #544

Closed dimvar closed 5 years ago

dimvar commented 10 years ago

See thread here: https://groups.google.com/forum/#!topic/closure-compiler-discuss/Al990_NyydY

(function() {
  /** @typedef {number} */ var Num;
  /** @type {Num} */
  var n;
}());

We will fix this in the new type inference, but unlikely before then.

freshp86 commented 5 years ago

Are there any updates here? This is still an issue.

lauraharker commented 5 years ago

The original example seems to work now: https://closure-compiler-debugger.appspot.com/#input0%3D(function()%2520%257B%250A%2520%2520%252F**%2520%2540typedef%2520%257Bnumber%257D%2520*%252F%2520var%2520Num%253B%250A%2520%2520%252F**%2520%2540type%2520%257BNum%257D%2520*%252F%250A%2520%2520var%2520n%253B%250A%2520%2520n%2520%253D%2520'str'%253B%2520%252F%252F%2520type%2520mismatch%2520warning%250A%257D())%253B%26input1%26conformanceConfig%26externs%26refasterjs-template%26CHECK_TYPES%3Dtrue%26CLOSURE_PASS%3Dtrue%26PRESERVE_TYPE_ANNOTATIONS%3Dtrue%26PRETTY_PRINT%3Dtrue

What issue are you seeing?

freshp86 commented 5 years ago

What issue are you seeing?

This bug is still referenced in the Chromium codebase, as the reason we have to declare our typedefs in the global scope, see examples here.

I'll double check next week if the problem occurs within the context of the Chromium codebase if those typedefs our moved to the inner scope, and get back to you. Thanks.

freshp86 commented 5 years ago

FYI https://crbug.com/986481 filed to cleanup our codebase from the workarounds we introduced as a result of this bug. It does indeed seems mostly fixed. I am still seeing some non-working cases but have not created a minimal repro yet.

Let's keep this issue open, until https://crbug.com/986481 has been resolved.

lauraharker commented 5 years ago

Sounds good. Created internal Google issue http://b/138149699 for tracking in case this is still an issue.

SamB commented 5 years ago

FYI, this bug is also referenced in Chrome's src/ui/webui/resources/js/load_time_data.js.

freshp86 commented 5 years ago

@SamB : This is already mentioned a few comments above at https://github.com/google/closure-compiler/issues/544#issuecomment-513424995.

SamB commented 5 years ago

@freshp86: Huh, I had assumed that that link was to a list of search results (or a file that had to work around the bug multiple times), probably because it was labeled as "examples".

Anyway, my point was really that load_time_data.js didn't seem to be within the scope of https://crbug.com/986481, but is presumably just as good a reason to keep this bug open, and maybe somebody should open a bug about it?

freshp86 commented 5 years ago

A bug already exists on the Chromium side, see https://crbug.com/986481.

lauraharker commented 5 years ago

@SamB @freshp86

I created https://github.com/google/closure-compiler/issues/3449 (dealing with the ChromePass) and https://github.com/google/closure-compiler/issues/3450 to track specific cases where local types are not working correctly.

Closing this GitHub issue because the original repro case is now fixed, and in general local types work.