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-10970] Operators with unrelated precedence incorrectly allowed to be adjacent #53359

Closed
hamishknight opened this issue Jun 19, 2019 · 2 comments
Assignees
Labels
accepts invalid Bug: Accepts invalid bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@hamishknight
Copy link
Collaborator

Previous ID SR-10970
Radar None
Original Reporter @hamishknight
Type Bug
Status Closed
Resolution Done
Environment

Apple Swift version 5.1 (swiftlang-1100.0.212.5 clang-1100.0.28.2)

Target: x86_64-apple-darwin19.0.0

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, AcceptsInvalid, TypeChecker
Assignee @gregomni
Priority Medium

md5: d8463e32d8da4bff72b759edb5963e32

Issue Description:

In the following example we correctly diagnose the fact that we're using two adjacent operators with unrelated precedence:

precedencegroup PowerPrecedence {
  lowerThan: BitwiseShiftPrecedence
  higherThan: AdditionPrecedence
  associativity: right
}
infix operator ^^ : PowerPrecedence

extension Int {
  static func ^^ (lhs: Int, rhs: Int) -> Int {
    var result = 1
    for _ in 1...rhs { result *= lhs }
    return result
  }
}

// error: Adjacent operators are in unordered precedence groups
// 'PowerPrecedence' and 'MultiplicationPrecedence'
_ = 1 ^^ 3 * 4

However if we add another application of ^^, the code compiles:

_ = 1 ^^ 2 ^^ 3 * 4 // No error.

I believe this should also be diagnosed with the above error.

@belkadan
Copy link
Contributor

Yikes. And fixing it means a source-break, now…

@gregomni
Copy link
Collaborator

@belkadan: It looks like nothing in the current source compatibility suite actually hits this issue. (<https://github.com/apple/swift/pull/26603\>).

I'm not sure what the policy is on source-breaking changes like this. Ought the error in this case be conditional on a version check? Or just a warning? If there's a policy doc or a similar example you could point me at, that'd be very helpful. I haven't done any (purposeful) source-breakage since Swift 3->4 days.

@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
accepts invalid Bug: Accepts invalid bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants