Skip to content

Object.assign(target, "string") drops the string's indexed characters #94

@RealColdFry

Description

@RealColdFry

Repro:

const x = Object.assign({3: 'd'}, "abc");
return [x[0], x[1], x[2], x[3]];

Expected: ["a", "b", "c", "d"]
Actual: [nil, nil, nil, "d"]

Per ECMA-262 sec-object.assign, each source is passed through ToObject; for a primitive string, that yields a String wrapper whose own enumerable keys are the indexed characters "0" -> "a", "1" -> "b", etc. Our lualib helper __TS__ObjectAssign (extern/tstl/src/lualib/ObjectAssign.ts) guards with if (type(source) === "table") and silently skips everything else. Fork commit c3b3a8b added that guard to prevent a crash on false/nil (the { ...(cond && obj) } pattern) but did not add the string-wrapper path.

Fix: in __TS__ObjectAssign, handle type(source) === "string" by iterating its bytes/characters and writing each under its integer index.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions