slint-ui/slint · warning

Duplicated function name

Error message

Duplicated function name ${cb} on global ${global}

What it means

Public functions declared on an exported global are exposed as callable methods on the global's JS object. If the translated function name already exists on that object (collision with another function, callback, or property of the same global), the function is skipped and this warning is printed. The function will not be callable under the expected JS name.

Solutions

  1. Rename the colliding function inside the global's .slint declaration
  2. Use the warning text to find the duplicate in that global's code and de-duplicate
  3. Call the function through the raw instance's global function API if renaming is not feasible

Example fix

// before (file.slint)
export global Calc {
    public function compute(x: int) -> int;
    public function compute(x: length) -> length; // collides after translation
}
// after (file.slint)
export global Calc {
    public function compute-int(x: int) -> int;
    public function compute-length(x: length) -> length;
}
Defensive patterns

Strategy: validation

Validate before calling

const fnNames = globalFunctions.map(translateName);
const dupes = fnNames.filter((n, i) => fnNames.indexOf(n) !== i);
if (dupes.length) throw new Error(`Duplicate functions on global: ${dupes}`);

Type guard

function globalFunctionCallable(globalObj, name) {
  return typeof globalObj[name] === 'function';
}

Prevention

When it happens

Trigger: Calling loadFile() or loadSource() on a project where a global declares two functions translating to the same JS name, or a function named like an existing member of the same global.

Common situations: Case-only duplicates in global function names; a function whose name collides with a callback or property of the same global after kebab-to-camelCase translation.

Related errors


AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16). Data as JSON: /api/errors/d18e257e6b012b53. Report an issue: GitHub.

Appendix: source

Thrown at api/node/typescript/index.ts:599

                                                    globalName,
                                                    cb,
                                                    callback,
                                                );
                                            },
                                            enumerable: true,
                                        },
                                    );
                                }
                            });

                        instance!
                            .definition()
                            .globalFunctions(globalName)
                            ?.forEach((cb) => {
                                const functionName = translateName(cb);

                                if (globalObject[functionName] !== undefined) {
                                    console.warn(
                                        "Duplicated function name " +
                                            cb +
                                            " on global " +
                                            global,
                                    );
                                } else {
                                    Object.defineProperty(
                                        globalObject,
                                        translateName(cb),
                                        {
                                            get() {
                                                return function () {
                                                    return instance!.invokeGlobal(
                                                        globalName,
                                                        cb,
                                                        Array.from(arguments),
                                                    );
                                                };

View on GitHub (pinned to bb937076de)