[Migrator] Suggest String <-> Substring conversions

Some APIs that expected a String now expect a Substring and vice
versa. To ease the transition, emit fix-its on conversion errors
between these types that the migrator can pick up.

When converting from Substring -> String, suggest wrapping in
`String.init`.

When converting from String -> Substring, suggest appending the
void subscript `[]`. (This isn't implemented yet so this is
hidden behind a flag).

This can possibly be generalized later when converting between
some sequence and its subsequence, such as Array and ArraySlice,
for example.

rdar://problem/31665649
rdar://problem/31666638
This commit is contained in:
David Farler
2017-05-04 16:40:56 -07:00
parent e3026b97e1
commit be86bcac1d
12 changed files with 454 additions and 95 deletions

View File

@@ -884,6 +884,12 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
const FrontendOptions &FrontendOpts) {
using namespace options;
/// FIXME: Remove this flag when void subscripts are implemented.
/// This is used to guard preemptive testing for the fix-it.
if (Args.hasArg(OPT_fix_string_substring_conversion)) {
Opts.FixStringToSubstringConversions = true;
}
if (auto A = Args.getLastArg(OPT_swift_version)) {
auto vers = version::Version::parseVersionString(
A->getValue(), SourceLoc(), &Diags);