[globals] Remove global shape for Array.from

Type inference currently assumes that a `FunctionSignature`'s effects have no 
false positives. If a `mutate` effect is observed on a read-only place, Forget 
currently assumes this is an user error and 
[throws](https://github.com/facebook/react-forget/blob/207595e04e2be08b8f62bf21dac9d846b9651e43/forget/src/Inference/InferReferenceEffects.ts#L275-L281). 

Array.from is polymorphic -- its effects are dependent on the type of its 
parameters
This commit is contained in:
mofeiZ
2023-04-05 12:53:39 -04:00
parent 4505218911
commit 9d97015236
+9 -10
View File
@@ -87,16 +87,15 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
calleeEffect: Effect.Read,
}),
],
[
"from",
// Array.from(arrayLike, optionalFn, optionalThis)
addFunction(DEFAULT_SHAPES, [], {
positionalParams: [Effect.Mutate],
restParam: Effect.Read,
returnType: { kind: "Object", shapeId: BuiltInArrayId },
calleeEffect: Effect.Read,
}),
],
// https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.from
// Array.from(arrayLike, optionalFn, optionalThis) not added because
// the Effect of `arrayLike` is polymorphic i.e.
// - Effect.read if
// - it does not have an @iterator property and is array-like
// (i.e. has a length property)
/// - it is an iterable object whose iterator does not mutate itself
// - Effect.mutate if it is a self-mutative iterator (e.g. a generator
// function)
[
"of",
// Array.of(element0, ..., elementN)