Skip to content

Signed/unsigned overloads collapse to the same Mojo signature (duplicate-definition) #80

Description

@Tokarzewski

Severity: medium (found stress-testing against Topologic, #79)

int and unsigned int both map to Mojo's Int (and presumably Rust's i64/Zig's equivalent). When a C++ class overloads a method by signedness only, both overloads survive into the emitted target with an identical signature — a guaranteed duplicate-definition compile error.

Repro (from github.com/wassimj/Topologic, TopologicCore/include/Bitwise.h):

class Bitwise {
public:
    static int NOT(const int kArgument1);
    static unsigned int NOT(const unsigned int kArgument1);
};

transpile --source cpp --target mojo on the flattened header+source emits:

struct Bitwise(Copyable, Movable):
    def NOT(self, kArgument1: Int) -> Int:
        return -kArgument1

    def NOT(self, kArgument1: Int) -> Int:
        return -kArgument1

Two methods with the identical (Int) -> Int signature in the same struct — Mojo (and Rust/Zig, which don't support overloading by signedness either) will reject this as a redefinition.

Fix direction

Detect same-name methods/functions in a struct/module whose parameter+return signatures collapse to identical target types after the int/unsigned int → single-int-type simplification, and either:

  • rename the losing overload deterministically (e.g. suffix _u/_unsigned), or
  • refuse the construct (raise UnsupportedConstruct) rather than silently emitting code that won't compile — consistent with this project's stated "refuse rather than emit wrong code" philosophy.

Found via corpus-testing PR (branch claude/repo-review-n4ylcz) which also fixed several parser-level gaps (export-macro handling, std::list shim, header-guard stripping) surfaced by the same corpus.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions