mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Improve handling of initializers in @available(renamed:).
If we know the renamed thing is being called, we can just use "Foo(...)" in the resulting expression (rather than "Foo.init(...)").
This commit is contained in:
@@ -1115,6 +1115,12 @@ void swift::fixItAvailableAttrRename(TypeChecker &TC,
|
||||
|
||||
// Continue on to diagnose any argument label renames.
|
||||
|
||||
} else if (parsed.BaseName == TC.Context.Id_init.str() &&
|
||||
parsed.isMember() && CE) {
|
||||
// For initializers, replace with a "call" of the context type...but only
|
||||
// if we know we're doing a call (rather than a first-class reference).
|
||||
diag.fixItReplace(referenceRange, parsed.ContextName);
|
||||
|
||||
} else {
|
||||
// Just replace the base name.
|
||||
SmallString<64> baseReplace;
|
||||
|
||||
@@ -296,6 +296,9 @@ func unavailableMultiUnnamedSame(_ a: Int, _ b: Int) {} // expected-note {{here}
|
||||
@available(*, unavailable, renamed: "shinyLabeledArguments(_:_:)")
|
||||
func unavailableMultiNewlyUnnamed(a: Int, b: Int) {} // expected-note {{here}}
|
||||
|
||||
@available(*, unavailable, renamed: "Int.init(other:)")
|
||||
func unavailableInit(a: Int) {} // expected-note 2 {{here}}
|
||||
|
||||
|
||||
func testArgNames() {
|
||||
unavailableArgNames(a: 0) // expected-error {{'unavailableArgNames(a:)' has been renamed to 'shinyLabeledArguments(example:)'}} {{3-22=shinyLabeledArguments}} {{23-24=example}}
|
||||
@@ -317,6 +320,10 @@ func testArgNames() {
|
||||
unavailableMultiUnnamed(0, 1) // expected-error {{'unavailableMultiUnnamed' has been renamed to 'shinyLabeledArguments(example:another:)'}} {{3-26=shinyLabeledArguments}} {{27-27=example: }} {{30-30=another: }}
|
||||
unavailableMultiUnnamedSame(0, 1) // expected-error {{'unavailableMultiUnnamedSame' has been renamed to 'shinyLabeledArguments(_:_:)'}} {{3-30=shinyLabeledArguments}}
|
||||
unavailableMultiNewlyUnnamed(a: 0, b: 1) // expected-error {{'unavailableMultiNewlyUnnamed(a:b:)' has been renamed to 'shinyLabeledArguments(_:_:)'}} {{3-31=shinyLabeledArguments}} {{32-35=}} {{38-41=}}
|
||||
|
||||
unavailableInit(a: 0) // expected-error {{'unavailableInit(a:)' has been replaced by 'Int.init(other:)'}} {{3-18=Int}} {{19-20=other}}
|
||||
let fn = unavailableInit // expected-error {{'unavailableInit(a:)' has been replaced by 'Int.init(other:)'}} {{12-27=Int.init}}
|
||||
fn(a: 1)
|
||||
}
|
||||
|
||||
@available(*, unavailable, renamed: "shinyLabeledArguments()")
|
||||
|
||||
Reference in New Issue
Block a user