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-11488] Implicit inout allowed with expression pattern matching #53888

Open
hamishknight opened this issue Sep 19, 2019 · 3 comments
Open
Assignees
Labels
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-11488
Radar None
Original Reporter @hamishknight
Type Bug
Status In Progress
Resolution
Environment

Swift version 5.1-dev (LLVM c5340df2d1, Swift 0cbbb21723)
Target: x86_64-apple-darwin18.5.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee @theblixguy
Priority Medium

md5: 1c04b5748355a33fd8b2071e29f6d302

Issue Description:

The following is legal:

func ~= (pattern: inout Int, value: Int) -> Bool {
  pattern = value
  return true
}

var x = 0

switch 49 {
case x:
  print("yup")
default:
  print("nope")
}

print(x) // 49

But we probably shouldn't allow the pattern x to be used as an implicit inout argument. This is source breaking, but I would hope nobody is relying on this.

@belkadan
Copy link
Contributor

Yuck. @jckarter, as a core team member, you want to say that this is an acceptable source break?

@jckarter
Copy link
Member

Yeah, I think that's clearly a bug.

@theblixguy
Copy link
Collaborator

PR: #27332

I have also created a thread on swift-evolution to decide whether we should:

  1. Skip ~= functions that take the pattern inout

  2. Diagnose ~= functions with a fix-it to remove inout

The current implementation does (1) because its simpler, but I can update it to do (2) instead if that's preferable.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants