antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
16.98k stars 3.26k forks source link

[Swift] public override should override public method #2807

Open martinvw opened 4 years ago

martinvw commented 4 years ago

When trying to generate an xcframework from the Swift runtime and using that in my application I bumped into some nasty errors:

/Users/martinvw/Library/Developer/Xcode/DerivedData/test-acqlbgtzsvmmgafvduarmjnwwrtr/Build/Products/Debug-iphonesimulator/Antlr4.framework/Modules/Antlr4.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:244:19: error: initializer does not override a designated initializer from its superclass
  override public init()
  ~~~~~~~~        ^
/Users/martinvw/Library/Developer/Xcode/DerivedData/test-acqlbgtzsvmmgafvduarmjnwwrtr/Build/Products/Debug-iphonesimulator/Antlr4.framework/Modules/Antlr4.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:1089:31: error: initializer does not override a designated initializer from its superclass
  convenience override public init(_ target: Antlr4.ATNState)
              ~~~~~~~~        ^
/Users/martinvw/Library/Developer/Xcode/DerivedData/test-acqlbgtzsvmmgafvduarmjnwwrtr/Build/Products/Debug-iphonesimulator/Antlr4.framework/Modules/Antlr4.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:1558:21: error: initializer does not override a designated initializer from its superclass
    override public init()
    ~~~~~~~~        ^
/Users/martinvw/Library/Developer/Xcode/DerivedData/test-acqlbgtzsvmmgafvduarmjnwwrtr/Build/Products/Debug-iphonesimulator/Antlr4.framework/Modules/Antlr4.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:1684:19: error: initializer does not override a designated initializer from its superclass
  override public init(_ target: Antlr4.ATNState)
  ~~~~~~~~        ^
/Users/martinvw/Library/Developer/Xcode/DerivedData/test-acqlbgtzsvmmgafvduarmjnwwrtr/Build/Products/Debug-iphonesimulator/CsdYaraIOS.framework/Modules/CsdYaraIOS.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:4:8: error: failed to load module 'Antlr4'
import Antlr4

After a long search I ender up at: https://forums.swift.org/t/generated-swiftinterface-has-wrong-content/28543

Where the following message is the most relevant:

doesn't have a public init, and so calling DisposeBag's init an override is incorrect from outside the module. However, I'm not sure we actually implement this correctly (where calling DisposeBag's init from a convenience initializer works without being able to see DisposeBase's init), so the broken interface is potentially protecting you from this issue.

And also:

tested serval libraries and found it pretty common to get an error:

correct: lottie-ios, SnapKit got errors: Alamofire, SwiftyJSON, RxSwift Here's a detail description to reproduce the errors:

So the init methods in the parent classes should also be public, I can/will create a PR for that when desired.

martinvw commented 4 years ago

Or I might have misinterpreted the topic and it is a bug in Swift, see https://bugs.swift.org/browse/SR-11422

We can work around this using a branch that I prepared.