swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

[SR-14805] Compiler crashes with swift-frontend[17417:263137] -[NSNib _initWithNibNamed:bundle:options:] could not load the nibName: Mose.Titlebarviewcontroller in bundle (null). #57153

Closed swift-ci closed 3 years ago

swift-ci commented 3 years ago
Previous ID SR-14805
Radar None
Original Reporter Anders Hansson (JIRA User)
Type Bug
Status Resolved
Resolution Invalid
Environment % swift --version Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55) Target: x86_64-apple-darwin20.5.0
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 03ff9c8c50a750473f4a8d440addbbae

Issue Description:


import AppKit
import SwiftUI

@available(macOS 10.15, *)
struct Tabsview: View {
  var body: some View { Text("Hello world!") }
}

class Titlebarviewcontroller: NSTitlebarAccessoryViewController {

  override init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?) 
  { print("init");  super.init(nibName: nil, bundle: nil) }

  init() { print("viewcontroller-init"); super.init(nibName: nil, bundle: nil) }

  required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }

  override func loadView() { super.loadView(); self.view = NSView(); print("loadView") }

  var textfield: NSTextField?

  override func viewDidLoad() { super.viewDidLoad(); print("viewDidLoad") 
    let frame = NSRect(x: 10, y: 10, width: 100, height: 10)
    textfield = NSTextField(frame: frame)
    if let textfield = textfield {
     textfield.isBezeled = false
     textfield.drawsBackground = false
     textfield.isEditable = false
     textfield.isSelectable = false
     textfield.stringValue = "Search"
     self.view.addSubview(textfield)
    }
  }

  override func viewWillAppear() { super.viewWillAppear(); print("viewWillAppear") }

}

class Tabswindow: NSWindow { }

@available(macOS 10.15, *)
class Appdelegate: NSObject, NSApplicationDelegate {

   let accessory = Titlebarviewcontroller()
   let window = NSWindow()

   func applicationDidFinishLaunching(_ notification: Notification) {
     window.title = "Minimum forks"

     let appMenu = NSMenuItem()
     appMenu.submenu = NSMenu()
     appMenu.submenu?.addItem(NSMenuItem(title: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q"))
     let mainMenu = NSMenu(title: "Minimum")
     mainMenu.addItem(appMenu)
     NSApplication.shared.mainMenu = mainMenu
     let size = CGSize(width: 480, height: 270)
     window.setContentSize(size)
     window.styleMask = [.closable, .miniaturizable, .resizable, .titled]

     let customToolbar = NSToolbar()
     customToolbar.showsBaselineSeparator = false
     window.titlebarAppearsTransparent = true
     /* window.titleVisibility = .hidden */
     window.toolbar = customToolbar

     // accessory.view = NSView(frame: NSRect(x: 0, y: 0, width: 281, height: 50))
     // accessory.view.wantsLayer = true
     // accessory.view.layer?.backgroundColor = NSColor.red.cgColor
     // accessory.layoutAttribute = .right
     window.addTitlebarAccessoryViewController(accessory)
     print("\(accessory.view)")

     let view = NSHostingView(rootView: Tabsview())
     view.frame = CGRect(origin: .zero, size: size)
     view.autoresizingMask = [.height, .width]
     window.contentView!.addSubview(view)
     window.setFrameAutosaveName("Forks Window")
     window.center()
     window.makeKeyAndOrderFront(self)
     /* if let window = controller.window { window.delegate = delegate }
     controller.showWindow(self) */
     NSApp.setActivationPolicy(.regular)
     NSApp.activate(ignoringOtherApps: true)
   }
}

let app = NSApplication.shared
let delegate = Appdelegate()
app.delegate = delegate
app.run()
Minimum % swift ./Mose.swift
viewcontroller-init
2021-06-21 20:05:06.637 swift-frontend[17417:263137] -[NSNib _initWithNibNamed:bundle:options:] could not load the nibName: Mose.Titlebarviewcontroller in bundle (null).
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: /Library/Developer/CommandLineTools/usr/bin/swift-frontend -frontend -interpret ./Mose.swift -enable-objc-interop -sdk /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -color-diagnostics -target-sdk-version 11.3 -module-name Mose 
1.  Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)
2.  While running user code "./Mose.swift"
0  swift-frontend           0x000000010e167e85 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift-frontend           0x000000010e166e78 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x000000010e168446 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff20490d7d _sigtramp + 29
4  libsystem_platform.dylib 0x00007fdd5689f900 _sigtramp + 18446743928590887840
5  AppKit                   0x00007fff22ec7ef8 __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 857
6  AppKit                   0x00007fff2361ccc3 ___NSRunLoopObserverCreateWithHandler_block_invoke + 41
7  CoreFoundation           0x00007fff20543d31 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
8  CoreFoundation           0x00007fff20543bc5 __CFRunLoopDoObservers + 543
9  CoreFoundation           0x00007fff20543058 __CFRunLoopRun + 841
10 CoreFoundation           0x00007fff2054264c CFRunLoopRunSpecific + 563
11 HIToolbox                0x00007fff28780ab3 RunCurrentEventLoopInMode + 292
12 HIToolbox                0x00007fff287806e6 ReceiveNextEventCommon + 284
13 HIToolbox                0x00007fff287805b3 _BlockUntilNextEventMatchingListInModeWithFilter + 70
14 AppKit                   0x00007fff22d436f2 _DPSNextEvent + 864
15 AppKit                   0x00007fff22d41ec5 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1364
16 AppKit                   0x00007fff22d34239 -[NSApplication run] + 586
17 AppKit                   0x0000000114a810ad -[NSApplication run] + 18446603344573419710
18 swift-frontend           0x00000001093eb49b llvm::orc::runAsMain(int (*)(int, char**), llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::Optional<llvm::StringRef>) + 1387
19 swift-frontend           0x00000001093cfa4a 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 const&, swift::SILOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >&&) + 14474
20 swift-frontend           0x0000000109396375 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 2421
21 swift-frontend           0x00000001093880ab swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7275
22 swift-frontend           0x0000000109309e82 main + 1266
23 libdyld.dylib            0x00007fff20466f5d start + 1
24 libdyld.dylib            0x000000000000000c start + 18446603339974676656
zsh: illegal hardware instruction  swift ./Mose.swift
CodaFi commented 3 years ago

2021-06-21 20:05:06.637 swift-frontend[17417:263137] -[NSNib _initWithNibNamed:bundle:options:] could not load the nibName: Mose.Titlebarviewcontroller in bundle (null).

This is not a bug in Swift - the interpreter crashed because your code crashed!