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-5682] Passing self into superclass's initializer compiles differently on Swift 3 and Swift 4 #48252

Closed
swift-ci opened this issue Aug 14, 2017 · 5 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 regression swift 4.0

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5682
Radar rdar://problem/33876682
Original Reporter crazytonyli (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift 3.1 on Xcode 8, Swift 4.0 on Xcode 9 beta 5

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

md5: 94bb0322329c49394c756f3a272d4e98

Issue Description:

Not sure if this is a feature or a bug, below code can be compiled successfully on Swift 4.0, but not on Swift 3.1. Swift 3 compiler throws an error: 'self' used before super.init call.

protocol Foo: class {
}

class Bar {
  private weak var foo: Foo?

  init(foo f: Foo) {
    foo = f
  }
}

class Baz: Bar, Foo {
  private let value: Int

  init(value v: Int) {
    value = v
    super.init(foo: self) // <- Swift 3 throws an error: 'self' used before super.init call
  }
}
@belkadan
Copy link
Contributor

Bug! Thanks, Tony.

@swift-ci create

@slavapestov
Copy link
Member

Yeah, the Swift 3 behavior was correct.

@slavapestov
Copy link
Member

Reduced test case:

class Bar {
  init(foo f: AnyObject) {}
}

class Baz: Bar {
  init() {
    super.init(foo: self)
  }
}

@slavapestov
Copy link
Member

Now crashes in SILGen:

Accessed self via non-formal evaluation API after exclusively borrowing self?!
UNREACHABLE executed at /Users/slava/new/swift/lib/SILGen/SILGenExpr.cpp:838!
0  swift                    0x0000000105d6e6f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x0000000105d6edb6 SignalHandler(int) + 470
2  libsystem_platform.dylib 0x00007fff5e914f5a _sigtramp + 26
3  libsystem_platform.dylib 0x0000000108430600 _sigtramp + 2846996160
4  libsystem_c.dylib        0x00007fff5e74032a abort + 127
5  swift                    0x0000000105d0da60 LLVMInstallFatalErrorHandler + 0
6  swift                    0x0000000102e82f5c swift::Lowering::SILGenFunction::emitRValueForSelfInDelegationInit(swift::SILLocation, swift::CanType, swift::SILValue, swift::Lowering::SGFContext) + 828
7  swift                    0x0000000102e83c6f swift::Lowering::SILGenFunction::emitRValueForDecl(swift::SILLocation, swift::ConcreteDeclRef, swift::Type, swift::AccessSemantics, swift::Lowering::SGFContext) + 2303

@slavapestov
Copy link
Member

No longer crashes on master or 9.3 beta 4

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

No branches or pull requests

4 participants