google / google/closure-compiler

soyutils_usegoog.js does not pass new type inference

Open
#1,445 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

repro case adapted from:
https://github.com/google/closure-templates/blob/master/javascript/soyutils_usegoog.js#L646

``` js
/**
* @param {!Object} baseMap The original map to augment.
* @param {!Object} additionalMap A map containing the additional mappings.
* @return {!Object} An augmented map containing both the original and
* additional mappings.
*/
var $$augmentMap = function(baseMap, additionalMap) {

// Create a new map whose '__proto__' field is set to baseMap.
/** @constructor */
function TempCtor() {}
TempCtor.prototype = baseMap;
var augmentedMap = new TempCtor();

// Add the additional mappings to the new map.
for (var key in additionalMap) {
augmentedMap[key] = additionalMap[key];
}

return augmentedMap;
};
```

gives the warning:

```
input0:12: WARNING - The right side in the assignment is not a subtype of the left side.
left side : Object{__defineGetter__:function(this:Object,string,Function|null):?, __defineSetter__:function(this:Object,string,Function|null):?, __lookupGetter__:function(this:Object,string):Function|null, __lookupSetter__:function(this:Object,string):Function|null, __noSuchMethod__:function(this:Object,Function|null):*, __parent__:Object|null, __proto__:Object|null, constructor:Function|null, hasOwnProperty:function(this:Object,*):boolean, isPrototypeOf:function(this:Object,Object|null):boolean, propertyIsEnumerable:function(this:Object,string):boolean, toJSON:function(this:Object,string|undefined=):*, toLocaleString:function(this:Object):string, toSource:function(this:Object):string, toString:function(this:*):string, unwatch:function(this:Object,string):?, valueOf:function(this:Object):*, watch:function(this:Object,string,Function|null):?}
right side : Object

TempCtor.prototype = baseMap;
^
```

http://closure-compiler-debugger.appspot.com/#input0%3D%252F**%250A%2520*%2520%2540param%2520%257B!Object%257D%2520baseMap%2520The%2520original%2520map%2520to%2520augment.%250A%2520*%2520%2540param%2520%257B!Object%257D%2520additionalMap%2520A%2520map%2520containing%2520the%2520additional%2520mappings.%250A%2520*%2520%2540return%2520%257B!Object%257D%2520An%2520augmented%2520map%2520containing%2520both%2520the%2520original%2520and%250A%2520*%2520%2520%2520%2520%2520additional%2520mappings.%250A%2520*%252F%250Avar%2520%2524%2524augmentMap%2520%253D%2520function(baseMap%252C%2520additionalMap)%2520%257B%250A%250A%2520%2520%252F%252F%2520Create%2520a%2520new%2520map%2520whose%2520'__proto__'%2520field%2520is%2520set%2520to%2520baseMap.%250A%2520%2520%252F**%2520%2540constructor%2520*%252F%250A%2520%2520function%2520TempCtor()%2520%257B%257D%250A%2520%2520TempCtor.prototype%2520%253D%2520baseMap%253B%250A%2520%2520var%2520augmentedMap%2520%253D%2520new%2520TempCtor()%253B%250A%250A%2520%2520%252F%252F%2520Add%2520the%2520additional%2520mappings%2520to%2520the%2520new%2520map.%250A%2520%2520for%2520(var%2520key%2520in%2520additionalMap)%2520%257B%250A%2520%2520%2520%2520augmentedMap%255Bkey%255D%2520%253D%2520additionalMap%255Bkey%255D%253B%250A%2520%2520%257D%250A%250A%2520%2520return%2520augmentedMap%253B%250A%257D%253B%26input1%26conformanceConfig%26externs%26refasterjs-template%26includeDefaultExterns%3D1%26CHECK_SYMBOLS%3D1%26CHECK_TYPES%3D1%26CHECK_TYPES_NEW_INFERENCE%3D1%26CLOSURE_PASS%3D1%26LANG_IN_IS_ES6%3D1%26MISSING_PROPERTIES%3D1%26PRESERVE_TYPE_ANNOTATIONS%3D1%26PRETTY_PRINT%3D1%26TRANSPILE%3D1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.