HoriSun / closure-compiler

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

Variables of record types not understood #1287

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago

Original comment by dim...@google.com on 21 Mar 2014 at 5:38