mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
…at least in the specific case of initializers. Normally, clang validates that a SwiftNameAttr’s specified name seems to have the right number of argument labels for the declaration it’s applied to; if it doesn’t, it diagnoses and drops the attribute. However, this checking isn’t perfect because clang doesn’t know all of Clang Importer’s throwing rules. The upshot is that it’s possible to get a mismatched SwiftNameAttr into Clang Importer if the last parameter looks like an out parameter. This trips an assertion in asserts compilers, but release compilers get past that and don’t seem to notice the mismatch at all. Add code to the compiler to tolerate this condition, at least in initializers, by modifying the Swift name to have the correct number of argument labels and deprecating the declaration with a message explaining the problem. Fixes rdar://141124373.
41 lines
1.8 KiB
Swift
41 lines
1.8 KiB
Swift
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %S/Inputs/custom-modules -Xcc -w -typecheck -verify %s
|
|
|
|
import SwiftName
|
|
|
|
func test() {
|
|
// Function name remapping
|
|
drawString("hello", x: 3, y: 5)
|
|
drawString("hello", 3, 5) // expected-error{{missing argument labels 'x:y:' in call}}
|
|
|
|
// Enum name remapping.
|
|
var color: ColorKind = CT_red
|
|
var color2: ColorType = CT_red // expected-error{{'ColorType' has been renamed to 'ColorKind'}}{{15-24=ColorKind}}
|
|
|
|
// Enumerator remapping.
|
|
var excuse: HomeworkExcuse = .dogAteIt
|
|
excuse = .overslept // expected-error{{type 'HomeworkExcuse' has no member 'overslept'; did you mean 'Overslept'?}} {{13-22=Overslept}}
|
|
excuse = .tired
|
|
excuse = .tooHard // expected-error{{type 'HomeworkExcuse' has no member 'tooHard'; did you mean 'TooHard'?}} {{13-20=TooHard}}
|
|
excuse = .challenging
|
|
|
|
// Typedef-of-anonymous-type-name renaming
|
|
var p = Point()
|
|
var p2 = PointType() // FIXME: should provide Fix-It expected-error{{cannot find 'PointType' in scope}} {{none}}
|
|
|
|
// Initializers with incorrect argument count (rdar://141124373)
|
|
var p3 = Point(path: "/dev/zero", nil) // expected-warning {{'init(path:_:)' is deprecated: declared Swift name 'init(path:)' was adjusted to 'init(path:_:)' because it does not have the correct number of parameters (1 vs. 2); please report this to its maintainer}}
|
|
|
|
// Field name remapping
|
|
p.x = 7
|
|
|
|
// Typedef renaming
|
|
var mi: MyInt = 5
|
|
var mi2: my_int_t = 7 // expected-error{{'my_int_t' has been renamed to 'MyInt'}}{{12-20=MyInt}}
|
|
|
|
spuriousAPINotedSwiftName(0)
|
|
nicelyRenamedFunction("go apinotes!")
|
|
|
|
_ = AnonymousEnumConstant // expected-error {{'AnonymousEnumConstant' has been renamed to 'BoxForConstants.anonymousEnumConstant'}}
|
|
_ = BoxForConstants.anonymousEnumConstant // okay
|
|
}
|