Skip to content

codegen(wasm): a user fn named like a String builtin (e.g. trim) returning an array is refused as a ++ operand #853

Backlog

Description

@hyperpolymath

A user function named like a String builtin, but returning an array, is wrongly refused as a ++ operand on core wasm. The failure is loud: compilation fails.

fn trim(xs: [Int]) -> [Int] { xs }
pub fn main() -> () { let ys = trim([1]) ++ [2]; println(int_to_string(len(ys))); }

affinescript compile x.affine -o x.wasm fails with Code generation error; interp and Bun-ESM accept the program. Re-verified on main-based build 161eaaf.

Cause, found by the #836 work (PR #841): is_string_concat_operand in lib/codegen.ml recognises String-returning builtins by spelling alone (trim, to_lowercase, string_sub, …), without checking whether the program defines its own function of that name.

Fix: consult the user-binding check from PR #841 (user_binds), or the type channel, before treating a call as a String operand.


Generated by Claude Code

Activity

  1. added
    architecture
    bindings
    enhancement
    on Dec 1, 2026
  2. whatproblem-ai commented on Dec 1, 2026

    @whatproblem-ai

    Problem: On core wasm, a user-defined function that shares a name with a String builtin (e.g. trim) but returns an array is rejected as a ++ operand, and affinescript compile fails with Code generation error. Interp and Bun-ESM accept the same program (verified on 161eaaf). The cause is that is_string_concat_operand in lib/codegen.ml matches builtins by name alone.

    Expected: trim([1]) ++ [2] compiles to wasm as array concatenation and prints 2, the same as on interp and Bun-ESM.


    Clarity: 94%. Clear enough to work on.

    ⌨️ Commands · 💬 Have feedback? Tell us · 🎯 New here? Add WhatProblem to your repo · 🔒 Privacy

  3. added
    bug
    priority:p2
    scope:repo
    status:ready
    on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    architecturebindingsbugenhancementpriority:p2scope:repostatus:ready

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions