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-6400] catch should not allow patterns for types that don't conform to Error #48950

Closed
tjw opened this issue Nov 15, 2017 · 7 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers

Comments

@tjw
Copy link
Contributor

tjw commented Nov 15, 2017

Previous ID SR-6400
Radar None
Original Reporter @tjw
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 9.2b2

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

md5: 7c4dde448ce9f350447079c1c9107ee4

Issue Description:

struct X {}
func y(action: () throws -> Void) throws {
    do {
        try action()
    } catch is X {

    }
}

The `catch is X` should fail to build, since X does not conform to Error.

@tjw
Copy link
Contributor Author

tjw commented Nov 16, 2017

In particular, this is important since if you mess up your ObjC error domain/enum pair, then the catch statement will appear to be working when it will never catch anything.

I had:

extern NSErrorDomain const ODOErrorDomain;

typedef NS_ENUM(NSInteger, ODOError) {
    ...
    ODOUnableToFindObjectWithID,
    ...
};

and then `catch ODOError.unableToFindObjectWithID` would compile, but not actually catch anything.

@belkadan
Copy link
Contributor

Good motivation. @jckarter, @xedin, think this would be easy enough for a starter bug?

@xedin
Copy link
Member

xedin commented Nov 16, 2017

Yes, I think this should be easy enough!

@Cbieniak
Copy link
Contributor

Cbieniak commented Dec 7, 2017

Hi @tjw,

I've began looking into this one and was hoping you could tell me I'm on the right track.

My current line of thinking is that the change will have to occur around
here, specifically strengthening the pattern checks, but i'm honestly not too sure.

Any guidance or strategies to work with these kinds of issues would be much appreciated.

Cheers,
Christian

@tjw
Copy link
Contributor Author

tjw commented Dec 7, 2017

@Cbieniak, that looks reasonable to me, but I'm no expert. One strategy that might help is to track down where in the compiler an error is generated when attempting to throw a value of a type that doesn't conform to Error.

That could help in making sure that the logic for testing the type is the same between the two spots.

@theblixguy
Copy link
Collaborator

PR: #23217

@theblixguy
Copy link
Collaborator

Fixed on master

@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 good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants