Skip to content

Commit d0c310c

Browse files
authored
---
yaml --- r: 339710 b: refs/heads/rxwei-patch-1 c: af7b461 h: refs/heads/master
1 parent cbde1a7 commit d0c310c

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: 22c099504667f8ce7a9af7048cbc3d23103c56b9
1018+
refs/heads/rxwei-patch-1: af7b461db2d25dc54e52ab50026e569505abb7eb
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/lib/Sema/CodeSynthesis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,7 @@ PropertyDelegateBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
17941794
VarDecl *storageVar = nullptr;
17951795
if (delegateInfo.delegateValueVar) {
17961796
storageVar = synthesizePropertyDelegateStorageDelegateProperty(
1797-
ctx, var, delegateType, delegateInfo.delegateValueVar);
1797+
ctx, var, storageType, delegateInfo.delegateValueVar);
17981798
}
17991799

18001800
// Get the property delegate information.

branches/rxwei-patch-1/stdlib/public/core/StringBridge.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ internal func _cocoaStringCopyUTF8(
9090
return len == converted ? count : nil
9191
}
9292

93+
@_effects(readonly)
94+
internal func _cocoaStringUTF8Count(
95+
_ target: _CocoaString,
96+
range: Range<Int>
97+
) -> Int? {
98+
var count = 0
99+
let len = _stdlib_binary_CFStringGetLength(target)
100+
let converted = _swift_stdlib_CFStringGetBytes(
101+
target,
102+
_swift_shims_CFRange(location: range.startIndex, length: range.count),
103+
kCFStringEncodingUTF8,
104+
0,
105+
0,
106+
UnsafeMutablePointer<UInt8>(Builtin.inttoptr_Word(0._builtinWordValue)),
107+
0,
108+
&count
109+
)
110+
return converted == len ? count : nil
111+
}
112+
93113
@_effects(readonly)
94114
internal func _cocoaStringCompare(
95115
_ string: _CocoaString, _ other: _CocoaString

branches/rxwei-patch-1/stdlib/public/core/StringUTF8View.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,31 @@ extension String.UTF8View {
470470
@_effects(releasenone)
471471
internal func _foreignDistance(from i: Index, to j: Index) -> Int {
472472
_internalInvariant(_guts.isForeign)
473+
474+
#if _runtime(_ObjC)
475+
// Currently, foreign means NSString
476+
if let count = _cocoaStringUTF8Count(
477+
_guts._object.cocoaObject,
478+
range: i._encodedOffset ..< j._encodedOffset
479+
) {
480+
//_cocoaStringUTF8Count gave us the scalar aligned count, but we still
481+
//need to compensate for sub-scalar indexing, e.g. if `i` is in the middle
482+
//of a two-byte UTF8 scalar.
483+
let refinedCount = count - (i.transcodedOffset + j.transcodedOffset)
484+
_internalInvariant(refinedCount == _distance(from: i, to: j))
485+
return refinedCount
486+
}
487+
#endif
488+
473489
return _distance(from: i, to: j)
490+
474491
}
475492

476493
@usableFromInline @inline(never)
477494
@_effects(releasenone)
478495
internal func _foreignCount() -> Int {
479496
_internalInvariant(_guts.isForeign)
480-
return _distance(from: startIndex, to: endIndex)
497+
return _foreignDistance(from: startIndex, to: endIndex)
481498
}
482499
}
483500

branches/rxwei-patch-1/test/decl/var/property_delegates.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,26 @@ func testStorageRef(tsr: TestStorageRef) {
667667
_ = tsr.$$x // expected-error{{'$$x' is inaccessible due to 'private' protection level}}
668668
}
669669

670+
// rdar://problem/50873275 - crash when using wrapper with delegateValue in
671+
// generic type.
672+
@_propertyDelegate
673+
struct InitialValueWrapperWithStorageRef<T> {
674+
var value: T
675+
676+
init(initialValue: T) {
677+
value = initialValue
678+
}
679+
680+
var delegateValue: Wrapper<T> {
681+
return Wrapper(value: value)
682+
}
683+
}
684+
685+
struct TestGenericStorageRef<T> {
686+
struct Inner { }
687+
@InitialValueWrapperWithStorageRef var inner: Inner = Inner()
688+
}
689+
670690
// ---------------------------------------------------------------------------
671691
// Misc. semantic issues
672692
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)