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-3104] Postfix operators that start with ? or ! should not be allowed #45692

Closed
swift-ci opened this issue Nov 1, 2016 · 2 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself parser Area → compiler: The legacy C++ parser

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Nov 1, 2016

Previous ID SR-3104
Radar None
Original Reporter tonisuter (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1)

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

md5: 33e734cec0f42a845b74f772568d3003

Issue Description:

In Swift 3, one can declare a postfix operator that starts with a ? or a !, but as far as I can tell, there's no way to actually use such an operator:

postfix operator ?**
postfix func ?**(x: Int) -> Int { return x }
let x = 12
x?**            // error: use of unresolved operator '**'

postfix operator !**
postfix func !**(x: Int) -> Int { return x }
let x = 12
x!**            // error: use of unresolved operator '**'

The parser interprets the ? and the ! as part of an optional chaining expr or a forced value expr, respectively. Additionally, the Swift Programming Language book states:

"Although you can define custom operators that contain a question mark ?, they can’t consist of a single question mark character only. Additionally, although operators can contain an exclamation mark !, postfix operators cannot begin with either a question mark or an exclamation mark."

Thus, I think the compiler should prohibit the declaration of a postfix operator that starts with a question mark or an exclamation mark.

@belkadan
Copy link
Contributor

belkadan commented Nov 1, 2016

I believe @gregomni fixed this in dc239af.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Nov 1, 2016

Comment by Toni Suter (JIRA)

Ah I see. Great, thank you!

@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. compiler The Swift compiler in itself parser Area → compiler: The legacy C++ parser
Projects
None yet
Development

No branches or pull requests

2 participants