Skip to content

Conversation

@Hassnaa9
Copy link

@Hassnaa9 Hassnaa9 commented Jan 16, 2026

Summary

This PR addresses the issue of the generator crashing when encountering Swift operator declarations (e.g., +, ***, +=). It introduces a robust mechanism to sanitize illegal Objective-C identifiers and correctly parse operator symbols from the Swift SymbolGraph.

Changes

Parser

  • Added support for swift.func.op in parse_declarations.dart.
    I verified through SymbolGraph JSON analysis (see attached evidence) that swift.func.op symbols share the same structure as regular swift.func.
  • Reused parseMethodDeclaration with isStatic: true for these symbols, which is safe and consistent with Swift's static operator implementation.

Screenshot 1
Screenshot 2

UniqueNamer

  • Implemented a _sanitize method to transform non-alphanumeric characters into valid Objective-C identifiers.
  • Added a mapping dictionary for common operators (e.g., +plus, -minus).
  • Implemented a fallback mechanism to ASCII codes (opXX) for custom or unknown symbols to prevent naming collisions and illegal syntax.
  • Ensured that identifiers do not start with numbers (prefixed with n).
    fixes: [swift2objc] Support operator overloading #2947

Sanitize illegal Objective-C identifiers and map Swift operators to valid names.
@Hassnaa9 Hassnaa9 force-pushed the feature/operator-overload-conversion branch from 0b06e24 to 9d84eff Compare January 16, 2026 20:59
@Hassnaa9
Copy link
Author

@liamappelbe Can you check this PR please?
thanks in advance!

@github-actions
Copy link

PR Health

License Headers ✔️
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/hooks_runner/test_data/download_assets/hook/build.dart
pkgs/jni/test/debug_release_test.dart
pkgs/objective_c/example/command_line/lib/main.dart
pkgs/objective_c/lib/src/ns_input_stream.dart

This check can be disabled by tagging the PR with skip-license-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?

This check can be disabled by tagging the PR with skip-breaking-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

@coveralls
Copy link

Coverage Status

coverage: 81.707%. remained the same
when pulling 9d84eff on Hassnaa9:feature/operator-overload-conversion
into 4fe954c on dart-lang:main.

@liamappelbe
Copy link
Contributor

@Hassnaa9 You'll need to fix the analysis errors reported by the bot before the tests will run. Make sure to do dart analyze and dart format before you upload so that the tests will run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[swift2objc] Support operator overloading

3 participants