Skip to content

A defaulted operator == is dropped as "supplied by the language": C# a == b fails with CS0019 on a struct, and Python/JS compare by identity #399

Open

Description

@matt-edmondson

What's wrong

FunctionDefinition.Defaulted on == means memberwise equality, as C++ = default provides. Several generators replace it with a comment and nothing else:

Generator Location What it writes
C# Coder/Languages/CSharpGenerator.cs L1260-1265 operator == is supplied by the language, which C# expresses by not declaring it.
Python Coder/Languages/PythonGenerator.cs ~L753 "supplied by the language" note
JavaScript Coder/Languages/JavaScriptGenerator.cs ~L573 "supplied by the language" note
C Coder/Languages/CGenerator.cs ~L273 prototype bool Point_equal(const Point* self, Point other); with no definition, while the call site still writes a raw struct ==

None of these languages supplies memberwise equality:

  • C#: a struct has no == operator at all, so a == b fails with CS0019. A class gets reference equality instead.
  • Python: the default __eq__ compares identity.
  • JavaScript: === compares identity.

The Go note ("Go gives every type a zero value instead", GoGenerator.cs ~L983-987) describes defaulted constructors, not equality. Go's struct == does happen to compare members.

Repro

Reproduced as follows:

  • Input: struct Point { x, y }, a defaulted == that takes const Point&, and bool same(Point a, Point b) { return a == b; }.
  • C++: compiles with g++ -std=c++20.
  • C#: dotnet build fails with CS0019 "Operator '==' cannot be applied to operands of type 'Point' and 'Point'".
  • Python: same(Point(1,2), Point(1,2)) returns False.

Suggested fix / acceptance criteria

  • C#: synthesise memberwise == and != together with Equals/GetHashCode (or IEquatable<T>). A record already gets all of these.
  • Python: generate an __eq__ that compares the instance fields.
  • JavaScript: emit an equals method, and say in the note that === can't be overloaded.
  • C: emit a memberwise definition for Point_equal rather than only the prototype.
  • Go: fix the note's wording.
  • Tests: in each target, compile or run a == b on two equal values and assert the result is true.

Activity

  1. added
    bug
    on Oct 30, 2026
  2. matt-edmondson commented on Oct 31, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions