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-6219] ~= Validation #48771

Closed
kemchenj opened this issue Oct 25, 2017 · 1 comment
Closed

[SR-6219] ~= Validation #48771

kemchenj opened this issue Oct 25, 2017 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@kemchenj
Copy link

Previous ID SR-6219
Radar None
Original Reporter @kemchenj
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

macOS: 10.13

Xcode: 9.0.1

Swift: 4.0

Platform: iOS

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

md5: ec12a9bd69d96f0c235d53cffae03696

duplicates:

  • SR-626 No diagnostic for unconditional recursion

Issue Description:

I write a syntactic sugar to optimize pattern matching for Optional:

extension Optional {
    static func ~=(lhs: Wrapped, rhs: Optional<Wrapped>) -> Bool {
        guard let unwrappedValue = rhs else { return false }
        return lhs ~= unwrappedValue
    }
}

But the Wrapped may not have ~= function, but it still works in compile time:

struct Person {
    var name: String
}

var john.  : Person? = Person(name: "John")
var someone: Person  = Person(name: "Someone")

switch john {
case someone :
    print("Someone Named John")
default:
    print("")
}

At runtime, it will cause a stack overflow, keep calling Optional.~=, there is a snapshot in attachment.

@belkadan
Copy link
Contributor

I'm going to say SR-626 would have caught this issue!

@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
Projects
None yet
Development

No branches or pull requests

2 participants