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-7955] EXC_BAD_ACCESS while accessing property of a constrained protocol #50490

Closed
swift-ci opened this issue Jun 10, 2018 · 1 comment
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7955
Radar None
Original Reporter pavelhlavnicka (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

XCode Version 9.4 (9F1027a)

macOS 10.13.5 (17F77)

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

md5: fcb1e646cb39224c618fdec43f9e5bbd

duplicates:

  • SR-6816 Let protocols inherit from class types

Issue Description:

This issue has two related manifestations - I believe it's a single bug (or two closely related)

Consider playground like this (working)

class SomeClass {
}

protocol Foo: class { // <-- this line 4 affects everything
    var isFooable: Bool { get set }
}


class ConcreteClass: SomeClass, Foo {
    var isFooable: Bool = false
}

let instance: SomeClass = ConcreteClass()

if let foo = instance as? Foo {
    foo.isFooable = false
    foo.isFooable
}

1) now if we change line 4 to

protocol Foo where Self: SomeClass {

we get an error at line

foo.isFooable = false

claiming foo is a let constant though I believe AnyObject reference behavior should be inferred

2) if we now change the condition to

if var foo = instance as? Foo {

we get EXC_BAD_EXEC at the line where we read the value (surprisingly not where we assign it)

3) we change protocol declaration to

protocol Foo: class where Self: SomeClass {

now all is working but we get two warnings

  • first for the protocol declaration saying that Self: Any Class is redundant (but see 1) - it did not work if was not present

  • second we don not have to declare foo as var in the conditional binding, what makes sense and can be easily fixed indeed

@belkadan
Copy link
Contributor

@slavapestov, another for your group of "protocols constrained to classes isn't really supported yet"?

@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