Skip to content

Commit b7e4746

Browse files
committed
Downgrade type access checks to warnings in certain cases.
...to be compatible with Swift 3. Fortunately these cases are all safe; they're the cases that would all be 'fileprivate' in Swift 2. Finishes https://bugs.swift.org/browse/SR-2579, although we'll need a follow-up bug to turn this /back/ into an error in Swift 4.
1 parent eb1d127 commit b7e4746

File tree

3 files changed

+213
-48
lines changed

3 files changed

+213
-48
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,13 +1110,27 @@ ERROR(pattern_type_access,none,
11101110
"because its type uses "
11111111
"%select{a private|a fileprivate|an internal|PUBLIC}4 type",
11121112
(bool, bool, bool, Accessibility, Accessibility))
1113+
WARNING(pattern_type_access_warn,none,
1114+
"%select{%select{variable|constant}0|property}1 "
1115+
"%select{should be declared %select{private|fileprivate|internal|PUBLIC}4"
1116+
"|should not be declared %select{in this context|fileprivate|internal|public}3}2 "
1117+
"because its type uses "
1118+
"%select{a private|a fileprivate|an internal|PUBLIC}4 type",
1119+
(bool, bool, bool, Accessibility, Accessibility))
11131120
ERROR(pattern_type_access_inferred,none,
11141121
"%select{%select{variable|constant}0|property}1 "
11151122
"%select{must be declared %select{private|fileprivate|internal|PUBLIC}4"
11161123
"|cannot be declared %select{PRIVATE|fileprivate|internal|public}3}2 "
11171124
"because its type %5 uses "
11181125
"%select{a private|a fileprivate|an internal|PUBLIC}4 type",
11191126
(bool, bool, bool, Accessibility, Accessibility, Type))
1127+
WARNING(pattern_type_access_inferred_warn,none,
1128+
"%select{%select{variable|constant}0|property}1 "
1129+
"%select{should be declared %select{private|fileprivate|internal|PUBLIC}4"
1130+
"|should not be declared %select{in this context|fileprivate|internal|public}3}2 "
1131+
"because its type %5 uses "
1132+
"%select{a private|a fileprivate|an internal|PUBLIC}4 type",
1133+
(bool, bool, bool, Accessibility, Accessibility, Type))
11201134
ERROR(pattern_binds_no_variables,none,
11211135
"%select{property|global variable}0 declaration does not bind any "
11221136
"variables",
@@ -1156,6 +1170,13 @@ ERROR(type_alias_underlying_type_access,none,
11561170
"because its underlying type uses "
11571171
"%select{a private|a fileprivate|an internal|PUBLIC}2 type",
11581172
(bool, Accessibility, Accessibility))
1173+
WARNING(type_alias_underlying_type_access_warn,none,
1174+
"type alias %select{should be declared "
1175+
"%select{private|fileprivate|internal|PUBLIC}2"
1176+
"|should not be declared %select{PRIVATE|fileprivate|internal|public}1}0 "
1177+
"because its underlying type uses "
1178+
"%select{a private|a fileprivate|an internal|PUBLIC}2 type",
1179+
(bool, Accessibility, Accessibility))
11591180

11601181
// Subscripts
11611182
ERROR(subscript_type_access,none,
@@ -1165,6 +1186,13 @@ ERROR(subscript_type_access,none,
11651186
"because its %select{index|element type}3 uses "
11661187
"%select{a private|a fileprivate|an internal|PUBLIC}2 type",
11671188
(bool, Accessibility, Accessibility, bool))
1189+
WARNING(subscript_type_access_warn,none,
1190+
"subscript %select{should be declared "
1191+
"%select{private|fileprivate|internal|PUBLIC}2"
1192+
"|should not be declared %select{in this context|fileprivate|internal|public}1}0 "
1193+
"because its %select{index|element type}3 uses "
1194+
"%select{a private|a fileprivate|an internal|PUBLIC}2 type",
1195+
(bool, Accessibility, Accessibility, bool))
11681196

11691197
// Functions
11701198
ERROR(function_type_access,none,
@@ -1174,6 +1202,13 @@ ERROR(function_type_access,none,
11741202
"because its %select{parameter|result}4 uses "
11751203
"%select{a private|a fileprivate|an internal|PUBLIC}2 type",
11761204
(bool, Accessibility, Accessibility, unsigned, bool))
1205+
WARNING(function_type_access_warn,none,
1206+
"%select{function|method|initializer}3 "
1207+
"%select{should be declared %select{private|fileprivate|internal|PUBLIC}2"
1208+
"|should not be declared %select{in this context|fileprivate|internal|public}1}0 "
1209+
"because its %select{parameter|result}4 uses "
1210+
"%select{a private|a fileprivate|an internal|PUBLIC}2 type",
1211+
(bool, Accessibility, Accessibility, unsigned, bool))
11771212
WARNING(non_trailing_closure_before_default_args,none,
11781213
"closure parameter prior to parameters with default arguments will "
11791214
"not be treated as a trailing closure", ())
@@ -1304,6 +1339,12 @@ ERROR(protocol_refine_access,none,
13041339
"|%select{PRIVATE|fileprivate|internal|public}1 protocol cannot "
13051340
"refine}0 %select{a private|a fileprivate|an internal|PUBLIC}2 protocol",
13061341
(bool, Accessibility, Accessibility))
1342+
WARNING(protocol_refine_access_warn,none,
1343+
"%select{protocol should be declared "
1344+
"%select{private|fileprivate|internal|PUBLIC}2 because it refines"
1345+
"|%select{in this context|fileprivate|internal|public}1 protocol should not "
1346+
"refine}0 %select{a private|a fileprivate|an internal|PUBLIC}2 protocol",
1347+
(bool, Accessibility, Accessibility))
13071348
ERROR(protocol_property_must_be_computed_var,none,
13081349
"immutable property requirement must be declared as 'var' with a "
13091350
"'{ get }' specifier", ())
@@ -1337,6 +1378,12 @@ ERROR(associated_type_access,none,
13371378
"%select{a private|a fileprivate|an internal|PUBLIC}1 type in its "
13381379
"%select{default definition|requirement}2 ",
13391380
(Accessibility, Accessibility, unsigned))
1381+
WARNING(associated_type_access_warn,none,
1382+
"associated type in "
1383+
"%select{a private|a fileprivate|an internal|a public}0 protocol uses "
1384+
"%select{a private|a fileprivate|an internal|PUBLIC}1 type in its "
1385+
"%select{default definition|requirement}2 ",
1386+
(Accessibility, Accessibility, unsigned))
13401387

13411388
NOTE(bad_associated_type_deduction,none,
13421389
"unable to infer associated type %0 for protocol %1",
@@ -1496,6 +1543,13 @@ ERROR(generic_param_access,none,
14961543
"because its generic %select{parameter|requirement}4 uses "
14971544
"%select{a private|a fileprivate|an internal|PUBLIC}3 type",
14981545
(DescriptiveDeclKind, bool, Accessibility, Accessibility, bool))
1546+
WARNING(generic_param_access_warn,none,
1547+
"%0 %select{should be declared "
1548+
"%select{private|fileprivate|internal|PUBLIC}3"
1549+
"|should not be declared %select{in this context|fileprivate|internal|public}2}1 "
1550+
"because its generic %select{parameter|requirement}4 uses "
1551+
"%select{a private|a fileprivate|an internal|PUBLIC}3 type",
1552+
(DescriptiveDeclKind, bool, Accessibility, Accessibility, bool))
14991553

15001554
ERROR(override_multiple_decls_base,none,
15011555
"declaration %0 cannot override more than one superclass declaration",
@@ -1688,6 +1742,10 @@ ERROR(enum_case_access,none,
16881742
"enum case in %select{PRIVATE|a fileprivate|an internal|a public}0 enum "
16891743
"uses %select{a private|a fileprivate|an internal|PUBLIC}1 type",
16901744
(Accessibility, Accessibility))
1745+
WARNING(enum_case_access_warn,none,
1746+
"enum case in %select{a private|a fileprivate|an internal|a public}0 enum "
1747+
"uses %select{a private|a fileprivate|an internal|PUBLIC}1 type",
1748+
(Accessibility, Accessibility))
16911749
ERROR(enum_stored_property,none,
16921750
"enums may not contain stored properties", ())
16931751

@@ -1716,6 +1774,13 @@ ERROR(enum_raw_type_access,none,
17161774
"because its raw type uses "
17171775
"%select{a private|a fileprivate|an internal|PUBLIC}2 type",
17181776
(bool, Accessibility, Accessibility))
1777+
WARNING(enum_raw_type_access_warn,none,
1778+
"enum %select{should be declared "
1779+
"%select{private|fileprivate|internal|PUBLIC}2"
1780+
"|should not be declared %select{in this context|fileprivate|internal|public}1}0 "
1781+
"because its raw type uses "
1782+
"%select{a private|a fileprivate|an internal|PUBLIC}2 type",
1783+
(bool, Accessibility, Accessibility))
17191784

17201785
NOTE(enum_here,none,
17211786
"enum %0 declared here", (Identifier))
@@ -2650,6 +2715,13 @@ ERROR(class_super_access,none,
26502715
"because its superclass is "
26512716
"%select{private|fileprivate|internal|PUBLIC}2",
26522717
(bool, Accessibility, Accessibility))
2718+
WARNING(class_super_access_warn,none,
2719+
"class %select{should be declared "
2720+
"%select{private|fileprivate|internal|PUBLIC}2"
2721+
"|should not be declared %select{in this context|fileprivate|internal|public}1}0 "
2722+
"because its superclass is "
2723+
"%select{private|fileprivate|internal|PUBLIC}2",
2724+
(bool, Accessibility, Accessibility))
26532725
ERROR(dot_protocol_on_non_existential,none,
26542726
"cannot use 'Protocol' with non-protocol type %0", (Type))
26552727
ERROR(tuple_single_element,none,

0 commit comments

Comments
 (0)