HoriSun / closure-compiler

Automatically exported from code.google.com/p/closure-compiler
0 stars 0 forks source link

Could not determine the type of template/generic expression. #1282

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile the following example, copy-pasted from compiler documentation:

/**
 * @param {T} a
 * @return {T}
 * @template T
 */
function identity(a) { return a; };

alert(identity('abc'));

2. The compilation command I use is:

java.exe -jar closure_compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS 
--summary_detail_level 3 --warning_level VERBOSE --jscomp_error 
reportUnknownTypes --js test.js --js_output_file ./test_result.js

What is the expected output? What do you see instead?

I expect no error. Instead, I get the error:

test.js:6: ERROR - could not determine the type of this expression
function identity(a) { return a; };
                              ^

1 error(s), 0 warning(s), 83.3% typed

I expect '100% typed', instead I get '83.3% typed'.

What version of the product are you using? On what operating system?

java.exe -jar closure_compiler.jar --version
Closure Compiler (http://code.google.com/closure/compiler)
Version: v20140303
Built on: 2014/03/04 10:53

Windows 7

Please provide any additional information below.
My goal is to create 100% typed programs and it looks like this is impossible 
if using templates/generics. The identity function is the simplest example I 
could come up with, and it's even given in compiler's docs at 
https://developers.google.com/closure/compiler/docs/js-for-compiler. However, 
it looks like the compiler doesn't understand the templates and claims the 
expression type is unknown.

Original issue reported on code.google.com by closure....@gmail.com on 17 Mar 2014 at 5:43

GoogleCodeExporter commented 9 years ago
Currently, the compiler doesn't handle the generic type T precisely in the body 
of the parameterized method. This is fixed in the new type inference (which is 
still experimental and under development, so you'll have to wait until it 
becomes the default).

Original comment by dim...@google.com on 19 Mar 2014 at 11:25