What steps will reproduce the problem?
1. Compile this example:
/**
@typedef {{ mandatory:number, optional: (number|undefined) }}
*/
var Record;
/** @param {!Record} x */
function f(x){ alert(JSON.stringify(x)); }
f({ mandatory: 7 }); //This is perfectly understood by the compiler.
/** @type{ !Record } */
var r = { mandatory: 7 }; //This is not understood by the compiler.
2. Use the command:
java.exe -jar closure_compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS
--summary_detail_level 3 --warning_level VERBOSE --js test.js --js_output_file
./test_result.js
What is the expected output? What do you see instead?
I expect the compiler to understand record types with optional properties
everywhere, not just in direct function calls. In particular I expect it to
understand simple variables of record types. Instead, the compiler only
understands object literals passed directly as actual function arguments, but
not var initialized with the same object literal. The console output is:
test.js:12: WARNING - initializing variable
found : {mandatory: number}
required: {mandatory: number, optional: (number|undefined)}
var r = { mandatory: 7 };
^
0 error(s), 1 warning(s), 100.0% 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.
Original issue reported on code.google.com by closure....@gmail.com on 21 Mar 2014 at 5:35
Original issue reported on code.google.com by
closure....@gmail.com
on 21 Mar 2014 at 5:35