From 73a492dc4f8c109110c31d85735d486e775cd1ab Mon Sep 17 00:00:00 2001 From: Mark Lacey Date: Mon, 4 Dec 2017 14:55:29 -0800 Subject: [PATCH] For Swift 3/4 mode, do not treat IUOs in illegal positions as Optionals. Instead, just emit a deprecation warning and suggest switching to Optionals. The old behavior caused several projects to break, so before we change the behavior here we need to investigate whether we can mitigate most of those breaks. --- include/swift/AST/DiagnosticsSema.def | 8 +- lib/Sema/TypeCheckType.cpp | 22 ++---- test/Migrator/Inputs/API.json | 10 +-- test/Sema/diag_deprecated_iuo.swift | 109 +++++++++++++------------- test/type/protocol_composition.swift | 6 +- test/type/types.swift | 2 +- 6 files changed, 71 insertions(+), 86 deletions(-) diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index d41ccf7987f24..35d411ff0f8ca 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -3117,11 +3117,11 @@ WARNING(implicitly_unwrapped_optional_spelling_deprecated,none, WARNING(implicitly_unwrapped_optional_spelling_deprecated_with_fixit,none, "the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name", ()) -WARNING(implicitly_unwrapped_optional_spelling_decay_to_optional,none, - "'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead", ()) +WARNING(implicitly_unwrapped_optional_spelling_suggest_optional,none, + "using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead", ()) -WARNING(implicitly_unwrapped_optional_in_illegal_position_decay_to_optional,none, - "'!' is not allowed here; interpreting this as '?' instead", ()) +WARNING(implicitly_unwrapped_optional_in_illegal_position_suggest_optional,none, + "using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead", ()) ERROR(implicitly_unwrapped_optional_spelling_error,none, "the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use an explicit type followed by '!'", ()) diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp index 28d1106b20166..5bcfc48c00866 100644 --- a/lib/Sema/TypeCheckType.cpp +++ b/lib/Sema/TypeCheckType.cpp @@ -1130,14 +1130,6 @@ resolveTopLevelIdentTypeComponent(TypeChecker &TC, DeclContext *DC, auto id = comp->getIdentifier(); - // If we're compiling for Swift version < 5 and we have a mention of - // ImplicitlyUnwrappedOptional where it is not allowed, treat it as - // if it was spelled Optional. - if (id == TC.Context.Id_ImplicitlyUnwrappedOptional - && !options.contains(TypeResolutionFlags::AllowIUO) - && !TC.Context.isSwiftVersionAtLeast(5)) - id = TC.Context.Id_Optional; - NameLookupOptions lookupOptions = defaultUnqualifiedLookupOptions; if (options.contains(TypeResolutionFlags::KnownNonCascadingDependency)) lookupOptions |= NameLookupFlags::KnownPrivate; @@ -1239,7 +1231,7 @@ resolveTopLevelIdentTypeComponent(TypeChecker &TC, DeclContext *DC, } } else if (isa(comp)) { Diagnostic diag = - diag::implicitly_unwrapped_optional_spelling_decay_to_optional; + diag::implicitly_unwrapped_optional_spelling_suggest_optional; if (TC.Context.isSwiftVersionAtLeast(5)) diag = diag::implicitly_unwrapped_optional_spelling_in_illegal_position; @@ -1258,7 +1250,7 @@ resolveTopLevelIdentTypeComponent(TypeChecker &TC, DeclContext *DC, genericTyR->getAngleBrackets().End.getAdvancedLoc(1)); } else { Diagnostic diag = - diag::implicitly_unwrapped_optional_spelling_decay_to_optional; + diag::implicitly_unwrapped_optional_spelling_suggest_optional; if (TC.Context.isSwiftVersionAtLeast(5)) diag = diag:: @@ -2847,7 +2839,7 @@ Type TypeResolver::resolveImplicitlyUnwrappedOptionalType( TypeResolutionOptions options) { if (!options.contains(TypeResolutionFlags::AllowIUO)) { Diagnostic diag = diag:: - implicitly_unwrapped_optional_in_illegal_position_decay_to_optional; + implicitly_unwrapped_optional_in_illegal_position_suggest_optional; if (TC.Context.isSwiftVersionAtLeast(5)) diag = diag::implicitly_unwrapped_optional_in_illegal_position; @@ -2865,12 +2857,8 @@ Type TypeResolver::resolveImplicitlyUnwrappedOptionalType( if (!baseTy || baseTy->hasError()) return baseTy; Type uncheckedOptionalTy; - if (!options.contains(TypeResolutionFlags::AllowIUO)) - // Treat IUOs in illegal positions as optionals. - uncheckedOptionalTy = TC.getOptionalType(repr->getExclamationLoc(), baseTy); - else - uncheckedOptionalTy = TC.getImplicitlyUnwrappedOptionalType( - repr->getExclamationLoc(), baseTy); + uncheckedOptionalTy = + TC.getImplicitlyUnwrappedOptionalType(repr->getExclamationLoc(), baseTy); if (!uncheckedOptionalTy) return ErrorType::get(Context); diff --git a/test/Migrator/Inputs/API.json b/test/Migrator/Inputs/API.json index 12881277712cd..822b318f5ab60 100644 --- a/test/Migrator/Inputs/API.json +++ b/test/Migrator/Inputs/API.json @@ -319,7 +319,7 @@ "NodeKind": "Function", "NodeAnnotation": "WrapOptional", "ChildIndex": "1", - "LeftUsr": "s:6Cities05ExtraA0P6blibliySSSgAE_SStc1x_tF", + "LeftUsr": "s:6Cities05ExtraA0P6blibliySQySSGSSSg_SStc1x_tF", "LeftComment": "", "RightUsr": "", "RightComment": "", @@ -330,7 +330,7 @@ "NodeKind": "Function", "NodeAnnotation": "WrapOptional", "ChildIndex": "1", - "LeftUsr": "s:6Cities05ExtraA0P6blibliySSSgAE_SStc1x_tF", + "LeftUsr": "s:6Cities05ExtraA0P6blibliySQySSGSSSg_SStc1x_tF", "LeftComment": "", "RightUsr": "", "RightComment": "", @@ -341,7 +341,7 @@ "NodeKind": "Function", "NodeAnnotation": "WrapOptional", "ChildIndex": "1", - "LeftUsr": "s:6Cities05ExtraA0P6blibliySSSgAE_SStc1x_tF", + "LeftUsr": "s:6Cities05ExtraA0P6blibliySQySSGSSSg_SStc1x_tF", "LeftComment": "", "RightUsr": "", "RightComment": "", @@ -352,7 +352,7 @@ "NodeKind": "Function", "NodeAnnotation": "ImplicitOptionalToOptional", "ChildIndex": "1:0", - "LeftUsr": "s:6Cities05ExtraA0P6blibliySSSgAE_SStc1x_tF", + "LeftUsr": "s:6Cities05ExtraA0P6blibliySQySSGSSSg_SStc1x_tF", "LeftComment": "", "RightUsr": "", "RightComment": "", @@ -363,7 +363,7 @@ "NodeKind": "Function", "NodeAnnotation": "UnwrapOptional", "ChildIndex": "1:1:0", - "LeftUsr": "s:6Cities05ExtraA0P6blibliySSSgAE_SStc1x_tF", + "LeftUsr": "s:6Cities05ExtraA0P6blibliySQySSGSSSg_SStc1x_tF", "LeftComment": "", "RightUsr": "", "RightComment": "", diff --git a/test/Sema/diag_deprecated_iuo.swift b/test/Sema/diag_deprecated_iuo.swift index be357e0d38dcf..8a443041b53e5 100644 --- a/test/Sema/diag_deprecated_iuo.swift +++ b/test/Sema/diag_deprecated_iuo.swift @@ -27,10 +27,7 @@ struct Fine { let _: ImplicitlyUnwrappedOptional = 1 // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name}}{{8-36=}} {{39-39=!}} {{39-40=}} let _: ImplicitlyUnwrappedOptional = 1 // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use an explicit type followed by '!'}} -extension ImplicitlyUnwrappedOptional { // expected-warning {{'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead}}{{11-38=Optional}} - func unwrap() -> Wrapped { - return self.unsafelyUnwrapped - } +extension ImplicitlyUnwrappedOptional { // expected-warning {{using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead}}{{11-38=Optional}} } func functionSpelling( @@ -48,8 +45,8 @@ func functionSigil( // Not okay because '!' is not at the top level of the type. func functionSigilArray( - _: [Int!] // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{10-11=?}} -) -> [Int!] { // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{10-11=?}} + _: [Int!] // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{10-11=?}} +) -> [Int!] { // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{10-11=?}} return [1] } @@ -68,12 +65,12 @@ func genericFunctionSigil( func genericFunctionSigilArray( // FIXME: We validate these types multiple times resulting in multiple diagnostics - iuo: [T!] // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{10-11=?}} - // expected-warning@-1 {{'!' is not allowed here; interpreting this as '?' instead}}{{10-11=?}} - // expected-warning@-2 {{'!' is not allowed here; interpreting this as '?' instead}}{{10-11=?}} -) -> [T!] { // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{8-9=?}} - // expected-warning@-1 {{'!' is not allowed here; interpreting this as '?' instead}}{{8-9=?}} - // expected-warning@-2 {{'!' is not allowed here; interpreting this as '?' instead}}{{8-9=?}} + iuo: [T!] // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{10-11=?}} + // expected-warning@-1 {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{10-11=?}} + // expected-warning@-2 {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{10-11=?}} +) -> [T!] { // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{8-9=?}} + // expected-warning@-1 {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{8-9=?}} + // expected-warning@-2 {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{8-9=?}} return iuo } @@ -83,16 +80,16 @@ protocol P { } struct S : P { - typealias T = ImplicitlyUnwrappedOptional // expected-warning {{'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead}}{{17-45=}} {{48-48=?}} {{48-49=}} - typealias U = Optional> // expected-warning {{'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead}}{{26-54=}} {{57-57=?}} {{57-58=}} + typealias T = ImplicitlyUnwrappedOptional // expected-warning {{using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead}}{{17-45=}} {{48-48=?}} {{48-49=}} + typealias U = Optional> // expected-warning {{using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead}}{{26-54=}} {{57-57=?}} {{57-58=}} - typealias V = Int! // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{20-21=?}} - typealias W = Int!? // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{20-21=?}} + typealias V = Int! // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{20-21=?}} + typealias W = Int!? // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{20-21=?}} var x: V var y: W - var fn1: (Int!) -> Int // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{16-17=?}} - var fn2: (Int) -> Int! // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{24-25=?}} + var fn1: (Int!) -> Int // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{16-17=?}} + var fn2: (Int) -> Int! // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{24-25=?}} subscript ( index: ImplicitlyUnwrappedOptional // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name}}{{12-40=}} {{43-43=!}} {{43-44=}} @@ -107,100 +104,100 @@ struct S : P { } } -func generic(_: T) where T.T == ImplicitlyUnwrappedOptional { } // expected-warning {{'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead}}{{40-68=}} {{71-71=?}} {{71-72=}} -func genericOptIUO(_: T) where T.U == Optional> {} // expected-warning {{'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead}}{{55-83=}} {{86-86=?}} {{86-87=}} +func generic(_: T) where T.T == ImplicitlyUnwrappedOptional { } // expected-warning {{using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead}}{{40-68=}} {{71-71=?}} {{71-72=}} +func genericOptIUO(_: T) where T.U == Optional> {} // expected-warning {{using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead}}{{55-83=}} {{86-86=?}} {{86-87=}} func testClosure() -> Int { return { (i: ImplicitlyUnwrappedOptional) // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name}}{{9-37=}} {{40-40=!}} {{40-41=}} - -> ImplicitlyUnwrappedOptional in // expected-warning {{'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead}}{{9-37=}} {{40-40=?}} {{40-41=}} + -> ImplicitlyUnwrappedOptional in // expected-warning {{using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead}}{{9-37=}} {{40-40=?}} {{40-41=}} return i }(1)! } -_ = Array() // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{14-15=?}} -let _: Array = [1] // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{17-18=?}} -_ = [Int!]() // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{9-10=?}} -let _: [Int!] = [1] // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{12-13=?}} -_ = Optional(nil) // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{17-18=?}} -let _: Optional = nil // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{20-21=?}} -_ = Int!?(0) // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{8-9=?}} -let _: Int!? = 0 // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{11-12=?}} +_ = Array() // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{14-15=?}} +let _: Array = [1] // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{17-18=?}} +_ = [Int!]() // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{9-10=?}} +let _: [Int!] = [1] // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{12-13=?}} +_ = Optional(nil) // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{17-18=?}} +let _: Optional = nil // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{20-21=?}} +_ = Int!?(0) // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{8-9=?}} +let _: Int!? = 0 // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{11-12=?}} _ = ( - Int!, // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{6-7=?}} - Float!, // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{8-9=?}} - String! // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{9-10=?}} + Int!, // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{6-7=?}} + Float!, // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{8-9=?}} + String! // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{9-10=?}} )(1, 2.0, "3") let _: ( - Int!, // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{6-7=?}} - Float!, // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{8-9=?}} - String! // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{9-10=?}} + Int!, // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{6-7=?}} + Float!, // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{8-9=?}} + String! // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{9-10=?}} ) = (1, 2.0, "3") struct Generic { init(_ t: T, _ u: U, _ c: C) {} } -_ = Generic(1, 2.0, "3") // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{19-20=?}} -let _: Generic = Generic(1, 2.0, "3") // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{22-23=?}} +_ = Generic(1, 2.0, "3") // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{19-20=?}} +let _: Generic = Generic(1, 2.0, "3") // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{22-23=?}} -func vararg(_ first: Int, more: Int!...) { // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{36-37=?}} +func vararg(_ first: Int, more: Int!...) { // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{36-37=?}} } -func varargIdentifier(_ first: Int, more: ImplicitlyUnwrappedOptional...) { // expected-warning {{'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead}}{{43-71=}} {{74-74=?}} {{74-75=}} +func varargIdentifier(_ first: Int, more: ImplicitlyUnwrappedOptional...) { // expected-warning {{using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead}}{{43-71=}} {{74-74=?}} {{74-75=}} } -func iuoInTuple() -> (Int!) { // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{26-27=?}} +func iuoInTuple() -> (Int!) { // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{26-27=?}} return 1 } -func iuoInTupleIdentifier() -> (ImplicitlyUnwrappedOptional) { // expected-warning {{'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead}}{{33-61=}} {{64-64=?}} {{64-65=}} +func iuoInTupleIdentifier() -> (ImplicitlyUnwrappedOptional) { // expected-warning {{using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead}}{{33-61=}} {{64-64=?}} {{64-65=}} return 1 } -func iuoInTuple2() -> (Float, Int!) { // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{34-35=?}} +func iuoInTuple2() -> (Float, Int!) { // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{34-35=?}} return (1.0, 1) } -func iuoInTuple2Identifier() -> (Float, ImplicitlyUnwrappedOptional) { // expected-warning {{'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead}}{{41-69=}} {{72-72=?}} {{72-73=}} +func iuoInTuple2Identifier() -> (Float, ImplicitlyUnwrappedOptional) { // expected-warning {{using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead}}{{41-69=}} {{72-72=?}} {{72-73=}} return (1.0, 1) } -func takesFunc(_ fn: (Int!) -> Int) -> Int { // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{26-27=?}} +func takesFunc(_ fn: (Int!) -> Int) -> Int { // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{26-27=?}} return fn(0) } -func takesFuncIdentifier(_ fn: (ImplicitlyUnwrappedOptional) -> Int) -> Int { // expected-warning {{'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead}}{{33-61=}} {{64-64=?}} {{64-65=}} +func takesFuncIdentifier(_ fn: (ImplicitlyUnwrappedOptional) -> Int) -> Int { // expected-warning {{using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead}}{{33-61=}} {{64-64=?}} {{64-65=}} return fn(0) } -func takesFunc2(_ fn: (Int) -> Int!) -> Int { // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{35-36=?}} +func takesFunc2(_ fn: (Int) -> Int!) -> Int { // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{35-36=?}} return fn(0)! } -func takesFunc2Identifier(_ fn: (Int) -> ImplicitlyUnwrappedOptional) -> Int { // expected-warning {{'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead}}{{42-70=}} {{73-73=?}} {{73-74=}} +func takesFunc2Identifier(_ fn: (Int) -> ImplicitlyUnwrappedOptional) -> Int { // expected-warning {{using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead}}{{42-70=}} {{73-73=?}} {{73-74=}} return fn(0)! } -func returnsFunc() -> (Int!) -> Int { // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{27-28=?}} +func returnsFunc() -> (Int!) -> Int { // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{27-28=?}} return { $0! } } -func returnsFuncIdentifier() -> (ImplicitlyUnwrappedOptional) -> Int { // expected-warning {{'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead}}{{34-62=}} {{65-65=?}} {{65-66=}} +func returnsFuncIdentifier() -> (ImplicitlyUnwrappedOptional) -> Int { // expected-warning {{using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead}}{{34-62=}} {{65-65=?}} {{65-66=}} return { $0! } } -func returnsFunc2() -> (Int) -> Int! { // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}}{{36-37=?}} +func returnsFunc2() -> (Int) -> Int! { // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}}{{36-37=?}} return { $0 } } -func returnsFunc2Identifier() -> (Int) -> ImplicitlyUnwrappedOptional { // expected-warning {{'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead}}{{43-71=}} {{74-74=?}} {{74-75=}} +func returnsFunc2Identifier() -> (Int) -> ImplicitlyUnwrappedOptional { // expected-warning {{using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead}}{{43-71=}} {{74-74=?}} {{74-75=}} return { $0 } } -let x = 1 as ImplicitlyUnwrappedOptional // expected-warning {{'ImplicitlyUnwrappedOptional' is not allowed here; interpreting this as 'Optional' instead}}{{14-41=Optional}} +let x = 1 as ImplicitlyUnwrappedOptional // expected-warning {{using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead}}{{14-41=Optional}} let y = x! let z: Int = x // expected-error {{value of optional type 'Int?' not unwrapped; did you mean to use '!' or '?'?}}{{15-15=!}} diff --git a/test/type/protocol_composition.swift b/test/type/protocol_composition.swift index 0d9e2c2220de2..aa49e39fc89d6 100644 --- a/test/type/protocol_composition.swift +++ b/test/type/protocol_composition.swift @@ -139,15 +139,15 @@ typealias E = protocol // expected-error {{'protocol<...>' composition synt typealias F = protocol // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}} {{15-33=Any}} typealias G = protocol.Type // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}} {{15-27=P1}} typealias H = protocol! // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}} {{15-28=P1!}} -// expected-warning@-1 {{'!' is not allowed here; interpreting this as '?' instead}} +// expected-warning@-1 {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}} typealias J = protocol.Protocol // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{15-31=(P1 & P2)}} typealias K = protocol? // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{15-32=(P1 & P2)?}} typealias T01 = P1.Protocol & P2 // expected-error {{non-protocol, non-class type 'P1.Protocol' cannot be used within a protocol-constrained type}} typealias T02 = P1.Type & P2 // expected-error {{non-protocol, non-class type 'P1.Type' cannot be used within a protocol-constrained type}} typealias T03 = P1? & P2 // expected-error {{non-protocol, non-class type 'P1?' cannot be used within a protocol-constrained type}} -typealias T04 = P1 & P2! // expected-error {{non-protocol, non-class type 'P2?' cannot be used within a protocol-constrained type}} -// expected-warning@-1 {{'!' is not allowed here; interpreting this as '?' instead}} +typealias T04 = P1 & P2! // expected-error {{non-protocol, non-class type 'P2!' cannot be used within a protocol-constrained type}} +// expected-warning@-1 {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}} typealias T05 = P1 & P2 -> P3 // expected-error {{single argument function types require parentheses}} {{17-17=(}} {{24-24=)}} typealias T06 = P1 -> P2 & P3 // expected-error {{single argument function types require parentheses}} {{17-17=(}} {{19-19=)}} typealias T07 = P1 & protocol // expected-error {{protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{22-38=P2 & P3}} diff --git a/test/type/types.swift b/test/type/types.swift index de9b136a4a437..5d16ceffd33fc 100644 --- a/test/type/types.swift +++ b/test/type/types.swift @@ -152,7 +152,7 @@ let tupleTypeWithNames = (age:Int, count:Int)(4, 5) let dictWithTuple = [String: (age:Int, count:Int)]() // typeexpr not being formed for postfix ! -let bb2 = [Int!](repeating: nil, count: 2) // expected-warning {{'!' is not allowed here; interpreting this as '?' instead}} +let bb2 = [Int!](repeating: nil, count: 2) // expected-warning {{using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead}} // inout allowed on function return type func r21560309(_ body: (_: inout Int) -> inout U) {} // expected-error {{'inout' may only be used on parameters}}