Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13350] @_exported import does not properly export custom operators #55790

Closed
swift-ci opened this issue Aug 5, 2020 · 4 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Aug 5, 2020

Previous ID SR-13350
Radar rdar://problem/66581584
Original Reporter Peter_Schorn (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode Version 11.6 (11E708)

macOS 10.15.6

Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: c145292c88b0c80e3366b424ca791f0b

duplicates:

  • SR-12132 @_exported does not respect custom operators

Issue Description:

Suppose you have a library with two targets: "Numerics" and "ReadModule". "Realmodule" has a public function named "realModuleTest". "Numerics" has a single file with the following line:

@_exported import RealModule

When you `import Numerics` into your project, you get access to "realModuleTest". This, as far as I understand, is the whole point of `@_exported import`.

However, when you define a custom operator inside of "RealModule", it does not get properly exported to "Numerics". Here is the custom operator I defined:

// RealModule/Real.swift

import Foundation

precedencegroup ExponentiativePrecedence {
  associativity: right
  higherThan: MultiplicationPrecedence
}

infix operator ** : ExponentiativePrecedence

public func ** (base: Double, power: Double) -> Double {
    return pow(base, power)
}

public func realModuleTest() {
    print("this function is defined in the real module")
}

I have uploaded this package to github: https://github.com/Peter-Schorn/OperatorAccessPackage

Please import the package into a command-line project and add the following to main.swift:

// main.swift
import Foundation
import Numerics

let x = 2.0
let y = 3.0

realModuleTest()  // works as expected

print(x ** y)  // error: "Operator is not a known binary operator"

You get the weird error described above. Surely this must be a bug, right?

UPDATE: I tried defining a custom infix and prefix operator and found that both were exported just fine. Therefore, this must be specific to infix operators.

@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Collaborator Author

swift-ci commented Aug 5, 2020

Comment by Peter Schorn (JIRA)

What does "@swift-ci create" mean?

@typesanitizer
Copy link

It syncs the Jira to Radar (which is Apple's internal bug-tracking system), so that it can be tracked together with Apple-internal bug reports as well as issues reported through other channels such as Feedback Assistant.

@hamishknight
Copy link
Collaborator

This was fixed on master by #31506 which uses a new operator lookup implementation as long as there's only a single candidate (but falls back to the old implementation in the multiple candidate case to preserve source compatibility). Therefore the example provided will compile on master.

The enabling of the new logic in all cases is being tracked internally by rdar://63604869.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

3 participants