-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Description
Hi,
try to compile the following test.js code:
/**
* @param {number} y
* @return {!Date}
*/
var a = function(y) {
var x;
switch(y) {
case 0: x = new Date(); break;
default: goog.asserts.fail('x would be undefined if we go beyond this line');
}
return x;
};with
java -jar /home/user/bin/closure-compiler/build/compiler.jar \
--compilation_level ADVANCED_OPTIMIZATIONS --jscomp_error=checkTypes \
test.js \
closure-library/closure/goog/asserts/asserts.js \
lib/closure-library/closure/goog/debug/error.js \
lib/closure-library/closure/goog/string/string.js \
lib/closure-library/closure/goog/dom/nodetype.js \
lib/closure-library/closure/goog/base.js
No error should arise, since the default case is a fail. But the compiler insists:
test.js:11: ERROR - inconsistent return type
found : (Date|undefined)
required: Date
return x;
^
1 error(s), 0 warning(s), 95.7% typed
Reactions are currently unavailable