Skip to content

Diagnose an invalid use of non-polymorphic constructors#13351

Merged
slavapestov merged 3 commits intoswiftlang:masterfrom
slavapestov:invalid-use-of-polymorphic-init
Dec 9, 2017
Merged

Diagnose an invalid use of non-polymorphic constructors#13351
slavapestov merged 3 commits intoswiftlang:masterfrom
slavapestov:invalid-use-of-polymorphic-init

Conversation

@slavapestov
Copy link
Contributor

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@jrose-apple
Copy link
Contributor

Seems like we'd need to downgrade this to a warning in Swift 4 mode.

@swiftlang swiftlang deleted a comment from swift-ci Dec 9, 2017
@swift-ci
Copy link
Contributor

swift-ci commented Dec 9, 2017

Build failed
Swift Test Linux Platform
Git Sha - 54de9a0b51488eeb44126e72d4cfe149d1804544

@slavapestov
Copy link
Contributor Author

@jrose-apple Here is a reduced version of the example from SILGen/protocol_extensions.swift:

import Foundation
  
class ObjCInitClass {
  @objc init(s: String) { self.x = s }

  var x: String
}

protocol ProtoDelegatesToObjC { }

extension ProtoDelegatesToObjC where Self : ObjCInitClass {
  init(string: String) {
    self.init(s: string)
  }
}

class X : ObjCInitClass, ProtoDelegatesToObjC {}

print(X(string: "hello world"))

The code compiles successfully with asserts off but the print() prints out a metatype and not an instance as expected. So it's just encountering undefined behavior. If I remove the @objc, I get a bus error instead. I don't think keeping this as a warning is a good idea, since there's no vtable entry for the initializer in this case and it's unlikely anyone is relying on this with good results.

@slavapestov slavapestov force-pushed the invalid-use-of-polymorphic-init branch from 54de9a0 to 336a97b Compare December 9, 2017 01:46
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@swift-ci
Copy link
Contributor

swift-ci commented Dec 9, 2017

Build failed
Swift Test OS X Platform
Git Sha - 54de9a0b51488eeb44126e72d4cfe149d1804544

@jrose-apple
Copy link
Contributor

Hm, okay, fair enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants