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-10582] EXC_BAD_ACCESS with protocol #52982

Closed
swift-ci opened this issue Apr 30, 2019 · 3 comments
Closed

[SR-10582] EXC_BAD_ACCESS with protocol #52982

swift-ci opened this issue Apr 30, 2019 · 3 comments
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 crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10582
Radar rdar://problem/50336780
Original Reporter Stormspirit (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Target: x86_64-apple-darwin18.2.0

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

md5: 0c6ed299cc244851e82ff4580ff3e023

relates to:

  • SR-4206 Override checking does not properly enforce requirements

Issue Description:

protocol Context {
  func isMe() -> Bool
}

class Binder<C> {
  func update<V>(with v: V) {}
}

class SubBinder<C: Context>: Binder<C> {
  override func update<V>(with v: V) where V: Sub<C> {
    // This is ok
    print(v.isMe())
    
    // EXC_BAD_ACCESS
    print(v.context.isMe())
  }
}

class Parent<C> {
  let context: C
  let binder: Binder<C>
  
  init(context: C, binder: Binder<C>) {
    self.context = context
    self.binder = binder
    binder.update(with: self)
  }
}

class Sub<C: Context>: Parent<C> {
  func isMe() -> Bool {
    return context.isMe()
  }
}

class C: Context {
  func isMe() -> Bool {
    return false
  }
}

let sub = Sub<C>(context: C(), binder: SubBinder<C>())
@theblixguy
Copy link
Collaborator

On Swift 5.1 (near-master):

Stack dump:
0.  Program arguments: /Users/suyashsrijan/Documents/swift-src/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/Debug/bin/swift -frontend -interpret /Users/suyashsrijan/Desktop/test.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name test -- -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
1.  Swift version 5.0-dev (LLVM 77814f897e, Swift d044696b30)
0  swift                    0x000000010dba0d75 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000010dba0035 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x000000010dba1358 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff58d63b5d _sigtramp + 29
4  libsystem_platform.dylib 0x0000000112c8ce48 _sigtramp + 3119682312
5  libsystem_platform.dylib 0x0000000112c8a67b _sigtramp + 3119672123
6  libsystem_platform.dylib 0x0000000112c8a7b7 _sigtramp + 3119672439
7  libsystem_platform.dylib 0x0000000112c8aa40 _sigtramp + 3119673088
8  libsystem_platform.dylib 0x0000000112c8a9a5 _sigtramp + 3119672933
9  libsystem_platform.dylib 0x0000000112c8a07c _sigtramp + 3119670588
10 swift                    0x000000010a171628 llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 456
11 swift                    0x000000010a174ab1 llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 1313
12 swift                    0x000000010a167091 swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, swift::IRGenOptions&, swift::SILOptions const&) + 3585
13 swift                    0x000000010a1570c1 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 14225
14 swift                    0x000000010a1528d2 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2978
15 swift                    0x000000010a0fd5a9 main + 729
16 libdyld.dylib            0x00007fff58b7e3d5 start + 1
17 libdyld.dylib            0x000000000000000d start + 2806520889

@belkadan
Copy link
Contributor

Ah, this is not valid code because the override adds additional requirements.

@slavapestov
Copy link
Member

We correctly reject this now in 5.2:

q.swift:10:17: error: overridden method 'update' has generic signature <C, V where C : Context, V : Sub<C>> which is incompatible with base method's generic signature <C, V>; expected generic signature to be <C, V where C : Context>
  override func update<V>(with v: V) where V: Sub<C> {
                ^
q.swift:6:8: note: overridden declaration is here
  func update<V>(with v: V) {}
       ^

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution
Projects
None yet
Development

No branches or pull requests

5 participants