Propagate functionResultType when resolving an abstract template property access. (#2527)

Summary:
Release notes: None

Added regression test.
This fix gets rid of a spurious internal RecoverableError.
Pull Request resolved: https://github.com/facebook/prepack/pull/2527

Reviewed By: trueadm

Differential Revision: D9622296

Pulled By: NTillmann

fbshipit-source-id: 0d0b7927f6c6f97d7ec43d4109dc52eda9ee7d13
This commit is contained in:
Nikolai Tillmann 2018-09-01 09:06:21 -07:00 committed by Facebook Github Bot
parent e845131e03
commit 067a378227
2 changed files with 17 additions and 0 deletions

View File

@ -1580,6 +1580,7 @@ export class PropertiesImplementation {
let realmGenerator = realm.generator;
invariant(realmGenerator);
invariant(value.operationDescriptor);
const functionResultType = value instanceof AbstractObjectValue ? value.functionResultType : undefined;
value = realmGenerator.deriveAbstract(value.types, value.values, value.args, value.operationDescriptor, {
isPure: true,
kind: "resolved",
@ -1592,6 +1593,10 @@ export class PropertiesImplementation {
args[savedIndex] = value;
value = AbstractValue.createAbstractConcreteUnion(realm, ...args);
}
if (functionResultType !== undefined) {
invariant(value instanceof AbstractObjectValue);
value.functionResultType = functionResultType;
}
if (realm.invariantLevel >= 1 && typeof P === "string" && !realm.hasBindingBeenChecked(O, P)) {
realm.markPropertyAsChecked(O, P);
realmGenerator.emitFullInvariant(O, P, value);

View File

@ -0,0 +1,12 @@
// add at runtime: let __obj = {f: function() { return 19; }};
let obj = global.__abstract
? __abstract({ f: __abstract(":number") }, "__obj")
: {
f: function() {
return 19;
},
};
let result = obj.f() + 23;
global.inspect = function() {
return 42;
};