mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Initializers should always have Swift names that have the special `DeclBaseName::createConstructor()` base name. Although there is an assertion to this effect in the constructor for ConstructorDecl, ClangImporter did not actually reject custom Swift names for initializers that violated this rule. This meant that asserts compilers would crash if they encountered code with an invalid `swift_name` attribute, while release compilers would silently accept them (while excluding these decls from certain checks since lookups that were supposed to find all initializers didn’t find them). Modify ClangImporter to diagnose this condition and ignore the custom Swift name.
29 lines
1.5 KiB
Swift
29 lines
1.5 KiB
Swift
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -I %/S/Inputs/custom-modules -Xcc -w -typecheck -verify %s -verify-additional-file %/S/Inputs/custom-modules%{fs-sep}SwiftName.h
|
|
|
|
import SwiftName
|
|
|
|
func test() {
|
|
// This particular instance method mapping previously caused a crash because
|
|
// of the trailing closure.
|
|
acceptsClosure(Foo(), test) // expected-error {{'acceptsClosure' has been replaced by instance method 'Foo.accepts(closure:)'}} {{3-17=(Foo()).accepts}} {{18-25=}} {{25-25=closure: }}
|
|
acceptsClosure(Foo()) {} // expected-error {{'acceptsClosure' has been replaced by instance method 'Foo.accepts(closure:)'}} {{3-17=(Foo()).accepts}} {{18-23=}}
|
|
|
|
Foo().accepts(closure: test)
|
|
Foo().accepts() {}
|
|
Foo().accepts {}
|
|
|
|
acceptsClosureStatic(test) // expected-error {{'acceptsClosureStatic' has been replaced by 'Foo.accepts(closure:)'}} {{3-23=Foo.accepts}}
|
|
acceptsClosureStatic() {} // expected-error {{'acceptsClosureStatic' has been replaced by 'Foo.accepts(closure:)'}} {{3-23=Foo.accepts}}
|
|
acceptsClosureStatic {} // expected-error {{'acceptsClosureStatic' has been replaced by 'Foo.accepts(closure:)'}} {{3-23=Foo.accepts}}
|
|
|
|
Foo.accepts(closure: test)
|
|
Foo.accepts() {}
|
|
Foo.accepts {}
|
|
|
|
_ = AnonymousEnumConstantObjC // expected-error {{'AnonymousEnumConstantObjC' has been renamed to 'Foo.anonymousEnumConstant'}}
|
|
_ = Foo.anonymousEnumConstant // okay
|
|
|
|
_ = Foo.initWithFoo() // expected-error {{type 'Foo' has no member 'initWithFoo'}}
|
|
_ = Foo.init(foo: ())
|
|
}
|