Skip to content

Commit 426b037

Browse files
DougGregorandrurogerz
authored andcommitted
Update expected diagnostics to match what SwiftIfConfig produces
For the most part, the differences between the diagnostics introduced by the C++ implementation and the new SwiftIfConfig implementation are cosmetic, so these are only wording changes. The one major difference is that we've dropped the warnings about potential typos in os/arch checks. For example, if one writes: #if os(bisionos) // ... #endif The C++ implementation will produce a warning "unknown operating system for build configuration 'os'" with a note asking "did you mean 'visionOS'"? These warnings rely on a static list of known operating systems and architectures, which is somewhat unfortunate: the whole point of these checks is that the Swift you're dealing with might not have support for those operating systems/architectures, so while these warnings can be helpful in a few cases, they also cause false positives when porting. Therefore, I chose not to bring them forward.
1 parent a8c2420 commit 426b037

13 files changed

+78
-87
lines changed

test/Parse/ConditionalCompilation/basicParseErrors.swift

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var x = 0
88
var y = 0
99
#endif
1010

11-
#if foo(BAR) // expected-error {{unexpected platform condition (expected 'os', 'arch', or 'swift')}}
11+
#if foo(BAR) // expected-error {{invalid conditional compilation expression}}
1212
var z = 0
1313
#endif
1414

@@ -27,7 +27,7 @@ func h() {}
2727
#else /* aaa */
2828
#endif /* bbb */
2929

30-
#if foo.bar() // expected-error {{unexpected platform condition (expected 'os', 'arch', or 'swift')}}
30+
#if foo.bar() // expected-error {{invalid conditional compilation expression}}
3131
.baz()
3232

3333
#endif
@@ -67,30 +67,23 @@ struct S {
6767
#else
6868
#endif
6969

70-
#if os(ios) // expected-warning {{unknown operating system for build configuration 'os'}} expected-note{{did you mean 'iOS'?}} {{8-11=iOS}}
70+
#if os(ios)
7171
#endif
7272

73-
#if os(uOS) // expected-warning {{unknown operating system for build configuration 'os'}} expected-note{{did you mean 'iOS'?}} {{8-11=iOS}}
73+
#if os(uOS)
7474
#endif
7575

76-
#if os(xxxxxxd) // expected-warning {{unknown operating system for build configuration 'os'}}
77-
// expected-note@-1{{did you mean 'Linux'?}} {{8-15=Linux}}
78-
// expected-note@-2{{did you mean 'FreeBSD'?}} {{8-15=FreeBSD}}
79-
// expected-note@-3{{did you mean 'Android'?}} {{8-15=Android}}
80-
// expected-note@-4{{did you mean 'OSX'?}} {{8-15=OSX}}
81-
// expected-note@-5{{did you mean 'OpenBSD'?}} {{8-15=OpenBSD}}
82-
// expected-note@-6{{did you mean 'xrOS'?}} {{8-15=xrOS}}
76+
#if os(xxxxxxd)
8377
#endif
8478

85-
#if os(bisionos) // expected-warning {{unknown operating system for build configuration 'os'}}
86-
// expected-note@-1{{did you mean 'visionOS'?}} {{8-16=visionOS}}
79+
#if os(bisionos)
8780

8881
#endif
8982

90-
#if arch(arn) // expected-warning {{unknown architecture for build configuration 'arch'}} expected-note{{did you mean 'arm'?}} {{10-13=arm}}
83+
#if arch(arn)
9184
#endif
9285

93-
#if _endian(mid) // expected-warning {{unknown endianness for build configuration '_endian'}} expected-note{{did you mean 'big'?}} {{13-16=big}}
86+
#if _endian(mid) // expected-warning {{unknown endianness for build configuration '_endian'}}
9487
#endif
9588

9689
LABEL: #if true // expected-error {{expected statement}}
@@ -104,7 +97,7 @@ func fn_j() {}
10497
#endif
10598
fn_j() // OK
10699

107-
#if foo || bar || nonExistent() // expected-error {{expected argument to platform condition}}
100+
#if foo || bar || nonExistent() // expected-error {{invalid conditional compilation expression}}
108101
#endif
109102

110103
#if FOO = false
@@ -123,47 +116,33 @@ undefinedFunc() // expected-error {{cannot find 'undefinedFunc' in scope}}
123116
#endif
124117

125118
/// Invalid platform condition arguments don't invalidate the whole condition.
119+
// expected-warning@+1{{unknown endianness}}
126120
#if !arch(arn) && !os(ystem) && !_endian(ness)
127-
// expected-warning@-1 {{unknown architecture for build configuration 'arch'}}
128-
// expected-note@-2 {{did you mean 'arm'?}} {{11-14=arm}}
129-
// expected-warning@-3 {{unknown operating system for build configuration 'os'}}
130-
// expected-note@-4 {{did you mean 'OSX'?}} {{23-28=OSX}}
131-
// expected-note@-5 {{did you mean 'PS4'?}} {{23-28=PS4}}
132-
// expected-note@-6 {{did you mean 'none'?}} {{23-28=none}}
133-
// expected-warning@-7 {{unknown endianness for build configuration '_endian'}}
134-
// expected-note@-8 {{did you mean 'big'?}} {{42-46=big}}
135121
func fn_k() {}
136122
#endif
137123
fn_k()
138124

139125
#if os(cillator) || arch(i3rm)
140-
// expected-warning@-1 {{unknown operating system for build configuration 'os'}}
141-
// expected-note@-2 {{did you mean 'macOS'?}} {{8-16=macOS}}
142-
// expected-note@-3 {{did you mean 'iOS'?}} {{8-16=iOS}}
143-
// expected-warning@-4 {{unknown architecture for build configuration 'arch'}}
144-
// expected-note@-5 {{did you mean 'arm'?}} {{26-30=arm}}
145-
// expected-note@-6 {{did you mean 'i386'?}} {{26-30=i386}}
146-
// expected-note@-7 {{did you mean 'visionOS'?}} {{8-16=visionOS}}
147126
func undefinedFunc() // ignored.
148127
#endif
149128
undefinedFunc() // expected-error {{cannot find 'undefinedFunc' in scope}}
150129

151-
#if os(simulator) // expected-warning {{unknown operating system for build configuration 'os'}} expected-note {{did you mean 'targetEnvironment'}} {{5-7=targetEnvironment}}
130+
#if os(simulator)
152131
#endif
153132

154-
#if arch(iOS) // expected-warning {{unknown architecture for build configuration 'arch'}} expected-note {{did you mean 'os'}} {{5-9=os}}
133+
#if arch(iOS)
155134
#endif
156135

157-
#if _endian(arm64) // expected-warning {{unknown endianness for build configuration '_endian'}} expected-note {{did you mean 'arch'}} {{5-12=arch}}
136+
#if _endian(arm64) // expected-warning {{unknown endianness for build configuration '_endian'}}
158137
#endif
159138

160-
#if targetEnvironment(_ObjC) // expected-warning {{unknown target environment for build configuration 'targetEnvironment'}} expected-note {{did you mean 'macabi'}} {{23-28=macabi}}
139+
#if targetEnvironment(_ObjC)
161140
#endif
162141

163-
#if os(iOS) || os(simulator) // expected-warning {{unknown operating system for build configuration 'os'}} expected-note {{did you mean 'targetEnvironment'}} {{16-18=targetEnvironment}}
142+
#if os(iOS) || os(simulator)
164143
#endif
165144

166-
#if arch(ios) // expected-warning {{unknown architecture for build configuration 'arch'}} expected-note {{did you mean 'os'}} {{5-9=os}} expected-note {{did you mean 'iOS'}} {{10-13=iOS}}
145+
#if arch(ios)
167146
#endif
168147

169148
#if FOO
@@ -179,5 +158,5 @@ if true {}
179158

180159
// rdar://83017601 Make sure we don't crash
181160
#if canImport()
182-
// expected-error@-1 {{expected argument to platform condition}}
161+
// expected-error@-1 {{'canImport' requires a module name}}
183162
#endif

test/Parse/ConditionalCompilation/can_import_in_inactive.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#endif
2222

2323
#if canImport(SomeModule)
24-
// CHECK: :[[@LINE-1]]:15: error: could not find module 'SomeModule' for target '{{.*}}'; found: i386
24+
// CHECK: :[[@LINE-1]]:{{.*}}: error: could not find module 'SomeModule' for target '{{.*}}'; found: i386
2525
#endif
2626

2727
import SomeModule

test/Parse/ConditionalCompilation/can_import_submodule.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ import A.B.C
4848
#endif
4949

5050

51-
#if canImport(A(_:).B) // expected-error@:15 {{unexpected platform condition argument: expected module name}}
51+
#if canImport(A(_:).B) // expected-error@:15 {{expected module name}}
5252
#endif
5353

54-
#if canImport(A.B(c: "arg")) // expected-error@:15 {{unexpected platform condition argument: expected module name}}
54+
#if canImport(A.B(c: "arg")) // expected-error@:15 {{expected module name}}
5555
#endif
5656

57-
#if canImport(A(b: 1, c: 2).B.C) // expected-error@:15 {{unexpected platform condition argument: expected module name}}
57+
#if canImport(A(b: 1, c: 2).B.C) // expected-error@:15 {{expected module name}}
5858
#endif
5959

60-
#if canImport(A.B("arg")(3).C) // expected-error@:15 {{unexpected platform condition argument: expected module name}}
60+
#if canImport(A.B("arg")(3).C) // expected-error@:15 {{expected module name}}
6161
#endif
6262

63-
#if canImport(A.B.C()) // expected-error@:15 {{unexpected platform condition argument: expected module name}}
63+
#if canImport(A.B.C()) // expected-error@:15 {{expected module name}}
6464
#endif

test/Parse/ConditionalCompilation/compiler_version.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,37 @@
3434
%#^*&
3535
#endif
3636

37-
#if _compiler_version("700a.*.10") // expected-error {{version component contains non-numeric characters}}
37+
#if _compiler_version("700a.*.10") // expected-error {{'_compiler_version' version check has invalid version '"700a.*.10"'}}
3838
#endif
3939

4040
#if _compiler_version("...") // expected-error {{found empty version component}}
41-
// expected-error@-1 {{found empty version component}}
42-
// expected-error@-2 {{found empty version component}}
4341
#endif
4442

45-
#if _compiler_version("") // expected-error {{version requirement is empty}}
43+
#if _compiler_version("") // expected-error {{found empty version component}}
4644
let y = 1
4745
#else
4846
let thisWillStillParseBecauseConfigIsError = 1
4947
#endif
5048

51-
#if _compiler_version("700.0.100") // expected-warning {{the second version component is not used for comparison in legacy compiler versions}} {{28-29=*}}
49+
#if _compiler_version("700.0.100") // expected-warning {{the second version component is not used for comparison in legacy compiler versions}}
5250
#endif
5351

54-
#if _compiler_version("5.7.100") // expected-warning {{the second version component is not used for comparison in legacy compiler versions; are you trying to encode a new Swift compiler version for compatibility with legacy compilers?}} {{24-27=5007.*}}
52+
#if _compiler_version("5.7.100") // expected-warning {{the second version component is not used for comparison in legacy compiler versions}}
5553
#endif
5654

5755
#if _compiler_version("700.*.1.1.1.1") // expected-error {{version must not have more than five components}}
5856
#endif
5957

60-
#if _compiler_version("9223372.*.1.1.1") // expected-error {{version component out of range: must be in [0, 9223371]}}
58+
#if _compiler_version("9223372.*.1.1.1") // expected-error {{compiler version component '9223372' is not in the allowed range 0...9223371}}
6159
#endif
6260

63-
#if _compiler_version("700.*.1000.1.1") // expected-error {{version component out of range: must be in [0, 999]}}
61+
#if _compiler_version("700.*.1000.1.1") // expected-error {{compiler version component '1000' is not in the allowed range 0...999}}
6462
#endif
6563

66-
#if _compiler_version("700.*.1.1000.1") // expected-error {{version component out of range: must be in [0, 999]}}
64+
#if _compiler_version("700.*.1.1000.1") // expected-error {{compiler version component '1000' is not in the allowed range 0...999}}
6765
#endif
6866

69-
#if _compiler_version("700.*.1.1.1000") // expected-error {{version component out of range: must be in [0, 999]}}
67+
#if _compiler_version("700.*.1.1.1000") // expected-error {{compiler version component '1000' is not in the allowed range 0...999}}
7068
#endif
7169

7270
// New style _compiler_version()

test/Parse/ConditionalCompilation/compoundName_swift4.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
/// Reject compound names.
44
#if BAR(_:) // expected-error@:5 {{invalid conditional compilation expression}}
5-
#elseif os(x:)(macOS) // expected-error@:9 {{unexpected platform condition (expected 'os', 'arch', or 'swift')}}
6-
#elseif os(Linux(foo:bar:)) // expected-error@:12 {{unexpected platform condition argument: expected identifier}}
5+
#elseif os(x:)(macOS) // expected-error@:9 {{invalid conditional compilation expression}}
6+
#elseif os(Linux(foo:bar:)) // expected-error@:9 {{'os' requires a single unlabeled argument for the operating system}}
77
#endif

test/Parse/ConditionalCompilation/language_version.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@
5353
%#^*&
5454
#endif
5555

56-
#if swift(">=7.1") // expected-error@:11 {{unexpected platform condition argument: expected a unary comparison '>=' or '<'; for example, '>=2.2' or '<2.2'}}
56+
#if swift(">=7.1") // expected-error@:5 {{'swift' requires a single unlabeled argument for the version comparison}}
5757
#endif
5858

59-
#if swift("<7.1") // expected-error@:11 {{unexpected platform condition argument: expected a unary comparison '>=' or '<'; for example, '>=2.2' or '<2.2'}}
59+
#if swift("<7.1") // expected-error@:5 {{'swift' requires a single unlabeled argument for the version comparison}}
6060
#endif
6161

62-
#if swift(">=2n.2") // expected-error@:11 {{unexpected platform condition argument: expected a unary comparison '>=' or '<'; for example, '>=2.2' or '<2.2'}}
62+
#if swift(">=2n.2") // expected-error@:5 {{'swift' requires a single unlabeled argument for the version comparison}}
6363
#endif
6464

65-
#if swift("") // expected-error@:11 {{unexpected platform condition argument: expected a unary comparison '>=' or '<'; for example, '>=2.2' or '<2.2'}}
65+
#if swift("") // expected-error@:5 {{'swift' requires a single unlabeled argument for the version comparison}}
6666
#endif
6767

6868
#if swift(>=2.2.1)
@@ -75,13 +75,13 @@ class C {
7575
#endif
7676
}
7777

78-
#if swift(>=2.0, *) // expected-error@:11 {{expected only one unlabeled argument to platform condition}}
78+
#if swift(>=2.0, *) // expected-error@:5 {{'swift' requires a single unlabeled argument for the version comparison}}
7979
#endif
8080

81-
#if swift(>=, 2.0) // expected-error@:11 {{expected only one unlabeled argument to platform condition}}
81+
#if swift(>=, 2.0) // expected-error@:5 {{'swift' requires a single unlabeled argument for the version comparison}}
8282
#endif
8383

84-
#if swift(version: >=2.0) // expected-error@:11 {{expected only one unlabeled argument to platform condition}}
84+
#if swift(version: >=2.0) // expected-error@:5 {{'swift' requires a single unlabeled argument for the version comparison}}
8585
#endif
8686

8787
protocol P {

test/Parse/ConditionalCompilation/macabiTargetEnv.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
// REQUIRES: OS=macosx || OS=maccatalyst
55

6-
#if targetEnvironment(macabi) // expected-warning {{'macabi' has been renamed to 'macCatalyst'}} {{23-29=macCatalyst}}
6+
#if targetEnvironment(macabi) // expected-warning {{'macabi' has been renamed to 'macCatalyst'}}
7+
// expected-note@-1{{replace with 'macCatalyst'}}{{23-29=macCatalyst}}
78
func underMacABI() {
89
foo() // expected-error {{cannot find 'foo' in scope}}
910
}
1011
#endif
1112

12-
#if !targetEnvironment(macabi) // expected-warning {{'macabi' has been renamed to 'macCatalyst'}} {{24-30=macCatalyst}}
13+
#if !targetEnvironment(macabi) // expected-warning {{'macabi' has been renamed to 'macCatalyst'}}
14+
// expected-note@-1{{replace with 'macCatalyst'}}{{24-30=macCatalyst}}
1315
// This block does not typecheck but the #if prevents it from
1416
// from being a compiler error.
1517
let i: SomeType = "SomeString" // no-error
@@ -29,8 +31,6 @@ let i: SomeType = "SomeString" // no-error
2931
#endif
3032

3133
#if os(macCatalyst)
32-
// expected-warning@-1 {{unknown operating system for build configuration 'os'}}
33-
// expected-note@-2 *{{did you mean}}
3434
func underOSMacCatalyst() {
3535
}
3636
#endif

test/Parse/ConditionalCompilation/pound-if-top-level-2.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// RUN: %target-typecheck-verify-swift
22

3-
#if 0 // expected-error {{'0' is not a valid conditional compilation expression, use 'false'}} {{5-6=false}}
3+
#if 0 // expected-error {{'0' is not a valid conditional compilation expression, use 'false'}}
4+
// expected-note@-1{{replace with Boolean literal 'false'}}{{5-6=false}}
45
let x = 1
56
#endif
67

7-
#if 1 // expected-error {{'1' is not a valid conditional compilation expression, use 'true'}} {{5-6=true}}
8+
#if 1 // expected-error {{'1' is not a valid conditional compilation expression, use 'true'}}
9+
// expected-note@-1{{replace with Boolean literal 'true'}}{{5-6=true}}
810
let x = 1
911
#endif
1012

test/Parse/ConditionalCompilation/simulatorTargetEnv.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,31 @@ var x = C()
1414
var y = x
1515

1616
#if os(iOS) && arch(i386)
17-
// expected-warning @-1 {{platform condition appears to be testing for simulator environment}} {{5-26=targetEnvironment(simulator)}}
17+
// expected-warning @-1 {{platform condition appears to be testing for simulator environment}}
18+
// expected-note@-2{{replace with 'targetEnvironment(simulator)'}}{{5-26=targetEnvironment(simulator)}}
1819
class C1 {}
1920
#endif
2021

2122
#if arch(i386) && os(iOS)
22-
// expected-warning @-1 {{platform condition appears to be testing for simulator environment}} {{5-26=targetEnvironment(simulator)}}
23+
// expected-warning @-1 {{platform condition appears to be testing for simulator environment}}
24+
// expected-note@-2{{replace with 'targetEnvironment(simulator)'}}{{5-26=targetEnvironment(simulator)}}
2325
class C2 {}
2426
#endif
2527

2628
#if arch(i386) && (os(iOS) || os(watchOS))
27-
// expected-warning @-1 {{platform condition appears to be testing for simulator environment}} {{5-43=targetEnvironment(simulator)}}
29+
// expected-warning @-1 {{platform condition appears to be testing for simulator environment}}
30+
// expected-note@-2{{replace with 'targetEnvironment(simulator)'}}{{5-43=targetEnvironment(simulator)}}
2831
class C3 {}
2932
#endif
3033

3134
#if (arch(x86_64) || arch(i386)) && (os(iOS) || os(watchOS) || os(tvOS))
32-
// expected-warning @-1 {{platform condition appears to be testing for simulator environment}} {{5-73=targetEnvironment(simulator)}}
35+
// expected-warning @-1 {{platform condition appears to be testing for simulator environment}}
36+
// expected-note@-2{{replace with 'targetEnvironment(simulator)'}}{{5-73=targetEnvironment(simulator)}}
3337
class C4 {}
3438
#endif
3539

3640
#if !(arch(x86_64) && os(tvOS))
37-
// expected-warning @-1 {{platform condition appears to be testing for simulator environment}} {{7-31=targetEnvironment(simulator)}}
41+
// expected-warning @-1 {{platform condition appears to be testing for simulator environment}}
42+
// expected-note@-2{{replace with 'targetEnvironment(simulator)'}}{{7-31=targetEnvironment(simulator)}}
3843
class C5 {}
3944
#endif

test/Parse/ifconfig_expr.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,35 +163,42 @@ func canImportVersioned() {
163163
let a = 1
164164
#endif
165165

166-
#if canImport(A, unknown: 2.2) // expected-error {{2nd parameter of canImport should be labeled as _version or _underlyingVersion}}
166+
#if canImport(A, unknown: 2.2) // expected-error {{second parameter of 'canImport' should be labeled as _version or _underlyingVersion}}
167167
let a = 1
168168
#endif
169169

170-
#if canImport(A, 2.2) // expected-error {{2nd parameter of canImport should be labeled as _version or _underlyingVersion}}
170+
171+
#if canImport(A,)
172+
let a = 1
173+
#endif
174+
175+
#if canImport(A, 2.2) // expected-error {{second parameter of 'canImport' should be labeled as _version or _underlyingVersion}}
171176
let a = 1
172177
#endif
173178

174-
#if canImport(A, 2.2, 1.1) // expected-error {{canImport can take only two parameters}}
179+
#if canImport(A, 2.2, 1.1) // expected-error {{'canImport' can take only two parameters}}
175180
let a = 1
176181
#endif
177182

183+
// expected-error@+1{{'canImport' version check has invalid version ''}}
178184
#if canImport(A, _version:) // expected-error {{expected expression in list of expressions}}
179185
let a = 1
180186
#endif
181187

182-
#if canImport(A, _version: "") // expected-error {{_version argument cannot be empty}}
188+
#if canImport(A, _version: "") // expected-error {{'canImport' version check has invalid version '""'}}
183189
let a = 1
184190
#endif
185191

186-
#if canImport(A, _version: >=2.2) // expected-error {{cannot parse module version '>=2.2'}}
192+
#if canImport(A, _version: >=2.2) // expected-error {{'canImport' version check has invalid version '>=2.2'}}
187193
let a = 1
188194
#endif
189-
195+
196+
// expected-error@+1{{'canImport' version check has invalid version '20A301'}}
190197
#if canImport(A, _version: 20A301) // expected-error {{'A' is not a valid digit in integer literal}}
191198
let a = 1
192199
#endif
193200

194-
#if canImport(A, _version: "20A301") // expected-error {{cannot parse module version '20A301'}}
201+
#if canImport(A, _version: "20A301") // expected-error {{'canImport' version check has invalid version '"20A301"'}}
195202
let a = 1
196203
#endif
197204
}

0 commit comments

Comments
 (0)