Files
swift-mirror/test/stdlib/StringCompatibilityDiagnostics4.swift
John McCall 4f4d64b93e Various improvements to the variable-is-never-mutated diagnostic.
The main fixes here are:
- we weren't looking through open-existentials in the l-value
- we weren't handling mutating gets correctly unless CSApply wrapped
  the base in an InOutExpr, which seems to be multifile-sensitive
- we were missing diagnostics in some cases involving subscripts

A better fix would be to re-introduce LValueAccessKind, but I wanted
a workable short-term fix that I could try to get into 5.1.

Fixes rdar://49482742, which is specific to the lazy-getter problem.
2019-04-08 18:43:24 -04:00

24 lines
1.0 KiB
Swift

// RUN: %target-swift-frontend -typecheck -swift-version 4 %s -verify
func testPopFirst() {
let str = "abc"
var charView: String.CharacterView // expected-warning{{'CharacterView' is deprecated: Please use String directly}}
charView = str.characters // expected-warning{{'characters' is deprecated: Please use String directly}}
dump(charView)
var substr = str[...]
_ = substr.popFirst() // ok
_ = substr.characters.popFirst() // expected-warning{{'characters' is deprecated: Please use Substring directly}}
_ = substr.unicodeScalars.popFirst() // ok
var charSubView: Substring.CharacterView // expected-warning{{'CharacterView' is deprecated: Please use Substring directly}}
charSubView = substr.characters // expected-warning{{'characters' is deprecated: Please use Substring directly}}
dump(charSubView)
var _ = String(str.utf8) ?? "" // expected-warning{{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}}
var _: String = String(str.utf8) // ok
}