Skip to content

JS backend: str.startswith(prefix, pos) drops the pos argument #324

@ldayton

Description

@ldayton

Summary

Python's two-argument str.startswith(prefix, pos) is transpiled without the pos argument across all backends. The position is silently dropped.

Reproduction

Source Python:

def _starts_with_at(s: str, pos: int, prefix: str) -> bool:
    return s.startswith(prefix, pos)

Transpiled JS:

return s.startsWith(prefix);  // should be s.startsWith(prefix, pos)

Transpiled Java:

return s.startsWith(prefix);  // should be s.startsWith(prefix, pos) — Java supports this natively

Transpiled Perl:

return (($s =~ /^\Q${\ $prefix}\E/) ? 1 : 0);  # anchored at ^, ignores $pos

Transpiled Ruby:

return s.start_with?(prefix)  # ignores pos

Impact

This is the single largest source of test failures in the Parable transpiled backends. The _starts_with_at helper is called from _is_expansion_start, which checks whether ${ appears at position pos. Without the position argument, it always checks from position 0, causing phantom matches everywhere.

Scope

Affects any Python code using the two-argument form of str.startswith() or str.endswith(). The single-argument form transpiles correctly. All four non-Python backends are affected.

Discovered via ldayton/Parable#413.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions