Skip to content

Commit ebfa459

Browse files
committed
CanImport: allow using string literal to indicate desired version
1 parent f832153 commit ebfa459

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

lib/Parse/ParseIfConfig.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,17 @@ static llvm::VersionTuple getCanImportVersion(TupleExpr *te,
9898
}
9999
return result;
100100
}
101+
StringRef verText;
101102
if (auto *nle = dyn_cast<NumberLiteralExpr>(subE)) {
102-
auto digits = nle->getDigitsText();
103-
if (result.tryParse(digits)) {
104-
if (D) {
105-
D->diagnose(nle->getLoc(), diag::canimport_version, digits);
106-
}
103+
verText = nle->getDigitsText();
104+
} else if (auto *sle= dyn_cast<StringLiteralExpr>(subE)) {
105+
verText = sle->getValue();
106+
}
107+
if (verText.empty())
108+
return result;
109+
if (result.tryParse(verText)) {
110+
if (D) {
111+
D->diagnose(subE->getLoc(), diag::canimport_version, verText);
107112
}
108113
}
109114
return result;

test/Parse/versioned_canimport.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,21 @@ func canImportVersioned() {
5656
let h = 1 // expected-warning {{initialization of immutable value 'h' was never used; consider replacing with assignment to '_' or removing it}}
5757
#endif
5858
}
59+
60+
func canImportVersionedString() {
61+
#if canImport(Foo, _version: "113.331")
62+
let a = 1
63+
#endif
64+
65+
#if canImport(Foo, _version: "113.3000")
66+
let b = 1
67+
#endif
68+
69+
#if canImport(Foo, _version: "4")
70+
let d = 1 // expected-warning {{initialization of immutable value 'd' was never used; consider replacing with assignment to '_' or removing it}}
71+
#endif
72+
73+
#if canImport(Foo, _version: "113.33")
74+
let e = 1 // expected-warning {{initialization of immutable value 'e' was never used; consider replacing with assignment to '_' or removing it}}
75+
#endif
76+
}

0 commit comments

Comments
 (0)