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-3003] Error for non-public implicit initializer is bogus #45593

Closed
tkrajacic opened this issue Oct 20, 2016 · 5 comments
Closed

[SR-3003] Error for non-public implicit initializer is bogus #45593

tkrajacic opened this issue Oct 20, 2016 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation

Comments

@tkrajacic
Copy link

Previous ID SR-3003
Radar None
Original Reporter @tkrajacic
Type Bug
Status Closed
Resolution Done
Environment

Xcode 8.1 beta (tested with latest snapshot and with Swift 3.0.1 beta)

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee None
Priority Medium

md5: 0db8051b4b4fb384f27f60a144ca4179

Issue Description:

I am trying to add an OptionSet to a framework. It needs to be public. This doesn't seem to be possible.

public struct Muppet: OptionSet {
    public let rawValue: Int
    
    public static let kermit    = Muppet(rawValue: 1 << 0)
    public static let piggy     = Muppet(rawValue: 1 << 1)

    public static let all: Muppet = [.kermit, .piggy]
}

gives the error

Playground execution failed: error: OptionSet.playground:1:15: error: initializer 'init(rawValue:)' must be declared public because it matches a requirement in public protocol 'OptionSet'
public struct Muppet: OptionSet {
              ^
              public 

error: OptionSet.playground:1:15: error: initializer 'init(rawValue:)' must be declared public because it matches a requirement in public protocol 'RawRepresentable'
public struct Muppet: OptionSet {
              ^
              public 


* thread #&#8203;1: tid = 0xd6fdc, 0x000000010b48b360 com.apple.dt.Xcode.PlaygroundStub-macosx`executePlayground, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
  * frame #&#8203;0: 0x000000010b48b360 com.apple.dt.Xcode.PlaygroundStub-macosx`executePlayground
    frame #&#8203;1: 0x000000010b48922a com.apple.dt.Xcode.PlaygroundStub-macosx`-[PlaygroundViewBridgeService execute] + 90
    frame #&#8203;2: 0x00007fffd3c4102c CoreFoundation`__invoking___ + 140
    frame #&#8203;3: 0x00007fffd3c40eb1 CoreFoundation`-[NSInvocation invoke] + 289
    frame #&#8203;4: 0x00007fffd3c5a376 CoreFoundation`-[NSInvocation invokeWithTarget:] + 54
    frame #&#8203;5: 0x00007fffe6e5718d ViewBridge`__68-[NSVB_ViewServiceImplicitAnimationDecodingProxy forwardInvocation:]_block_invoke + 47
    frame #&#8203;6: 0x00007fffe6e6878b ViewBridge`__runAnimationGroup_block_invoke + 21
    frame #&#8203;7: 0x00007fffd21977e3 AppKit`+[NSAnimationContext runAnimationGroup:] + 58
    frame #&#8203;8: 0x00007fffd18f1776 AppKit`+[NSAnimationContext runAnimationGroup:completionHandler:] + 85
    frame #&#8203;9: 0x00007fffe6e68767 ViewBridge`runAnimationGroup + 303
    frame #&#8203;10: 0x00007fffe6e56c94 ViewBridge`+[NSVB_View _animateWithAttributes:animations:completion:] + 507
    frame #&#8203;11: 0x00007fffe6e5710f ViewBridge`-[NSVB_ViewServiceImplicitAnimationDecodingProxy forwardInvocation:] + 156
    frame #&#8203;12: 0x00007fffd3c3f9ea CoreFoundation`___forwarding___ + 538
    frame #&#8203;13: 0x00007fffd3c3f748 CoreFoundation`__forwarding_prep_0___ + 120
    frame #&#8203;14: 0x00007fffd3c4102c CoreFoundation`__invoking___ + 140
    frame #&#8203;15: 0x00007fffd3c40eb1 CoreFoundation`-[NSInvocation invoke] + 289
    frame #&#8203;16: 0x00007fffd3c5a376 CoreFoundation`-[NSInvocation invokeWithTarget:] + 54
    frame #&#8203;17: 0x00007fffe6e2522b ViewBridge`-[NSVB_QueueingProxy forwardInvocation:] + 327
    frame #&#8203;18: 0x00007fffd3c3f9ea CoreFoundation`___forwarding___ + 538
    frame #&#8203;19: 0x00007fffd3c3f748 CoreFoundation`__forwarding_prep_0___ + 120
    frame #&#8203;20: 0x00007fffd3c4102c CoreFoundation`__invoking___ + 140
    frame #&#8203;21: 0x00007fffd3c40eb1 CoreFoundation`-[NSInvocation invoke] + 289
    frame #&#8203;22: 0x00007fffd3c5a376 CoreFoundation`-[NSInvocation invokeWithTarget:] + 54
    frame #&#8203;23: 0x00007fffd3c3f9ea CoreFoundation`___forwarding___ + 538
    frame #&#8203;24: 0x00007fffd3c3f748 CoreFoundation`__forwarding_prep_0___ + 120
    frame #&#8203;25: 0x00007fffd3c4102c CoreFoundation`__invoking___ + 140
    frame #&#8203;26: 0x00007fffd3c40eb1 CoreFoundation`-[NSInvocation invoke] + 289
    frame #&#8203;27: 0x00007fffd3c5a376 CoreFoundation`-[NSInvocation invokeWithTarget:] + 54
    frame #&#8203;28: 0x00007fffd3c3f9ea CoreFoundation`___forwarding___ + 538
    frame #&#8203;29: 0x00007fffd3c3f748 CoreFoundation`__forwarding_prep_0___ + 120
    frame #&#8203;30: 0x00007fffd3c4102c CoreFoundation`__invoking___ + 140
    frame #&#8203;31: 0x00007fffd3c40eb1 CoreFoundation`-[NSInvocation invoke] + 289
    frame #&#8203;32: 0x00007fffe6e6ce28 ViewBridge`withHintInProgress + 487
    frame #&#8203;33: 0x00007fffe6e6cb57 ViewBridge`__deferNSXPCInvocationOntoMainThread_block_invoke_2 + 233
    frame #&#8203;34: 0x00007fffe6dfe202 ViewBridge`+[NSViewServiceApplication withHostPID:invoke:] + 46
    frame #&#8203;35: 0x00007fffe6e6ca1a ViewBridge`__deferNSXPCInvocationOntoMainThread_block_invoke + 179
    frame #&#8203;36: 0x00007fffe6e6c607 ViewBridge`__deferBlockOntoMainThread_block_invoke_2 + 544
    frame #&#8203;37: 0x00007fffd3c633ac CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    frame #&#8203;38: 0x00007fffd3c44424 CoreFoundation`__CFRunLoopDoBlocks + 356
    frame #&#8203;39: 0x00007fffd3c43f66 CoreFoundation`__CFRunLoopRun + 1878
    frame #&#8203;40: 0x00007fffd3c435b4 CoreFoundation`CFRunLoopRunSpecific + 420
    frame #&#8203;41: 0x00007fffd31e4f6c HIToolbox`RunCurrentEventLoopInMode + 240
    frame #&#8203;42: 0x00007fffd31e4da1 HIToolbox`ReceiveNextEventCommon + 432
    frame #&#8203;43: 0x00007fffd31e4bd6 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 71
    frame #&#8203;44: 0x00007fffd18db5f5 AppKit`_DPSNextEvent + 1093
    frame #&#8203;45: 0x00007fffd1feb8eb AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1637
    frame #&#8203;46: 0x00007fffe6dff47a ViewBridge`-[NSViewServiceApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 102
    frame #&#8203;47: 0x00007fffd18cffbd AppKit`-[NSApplication run] + 926
    frame #&#8203;48: 0x00007fffd189aa8a AppKit`NSApplicationMain + 1237
    frame #&#8203;49: 0x00007fffe8ee68b3 libxpc.dylib`_xpc_objc_main + 775
    frame #&#8203;50: 0x00007fffe8ee52d0 libxpc.dylib`xpc_main + 494
    frame #&#8203;51: 0x00007fffe6e296b9 ViewBridge`-[NSXPCSharedListener resume] + 16
    frame #&#8203;52: 0x00007fffe6e042c9 ViewBridge`NSViewServiceApplicationMain + 3022
    frame #&#8203;53: 0x000000010b48b3a2 com.apple.dt.Xcode.PlaygroundStub-macosx`main + 34
    frame #&#8203;54: 0x00007fffe8c83255 libdyld.dylib`start + 1
    frame #&#8203;55: 0x00007fffe8c83255 libdyld.dylib`start + 1

and actually wants to insert another `public` after the `struct` keyword...
Removing `public` from the struct's definition compiles again, but then again I can't use the struct.

@belkadan
Copy link
Contributor

Implicitly-provided initializers are never public; if you want to use it from other frameworks, you'll have to write it explicitly. That fix-it is definitely wrong though!

@tkrajacic
Copy link
Author

Ah sorry for the mistake. Didn't know that. Is this documented somewhere? I just browsed through the Swift Programming Language book and the section on struct initializers doesn't mention that.

@louisdh
Copy link
Contributor

louisdh commented Jul 10, 2017

Just came across the same bogus fix-it, unfixed as of Swift 4.0 beta 2.

@tkrajacic
Copy link
Author

This is fixed in Swift 4.1 and Xcode 9.3

@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 diagnostics QoI Bug: Diagnostics Quality of Implementation
Projects
None yet
Development

No branches or pull requests

3 participants