Skip to content

Commit b39a6ed

Browse files
committed
Sema: Coerce base to rvalue when calling a DeclViaBridging overload kind
This code path is only used for a special purpose hack to make NSString members available on String. Since it is rarely exercised, it was broken.
1 parent 5cfd7b5 commit b39a6ed

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,13 +2555,14 @@ namespace {
25552555
auto selected = *selectedElt;
25562556
switch (selected.choice.getKind()) {
25572557
case OverloadChoiceKind::DeclViaBridge: {
2558+
base = cs.coerceToRValue(base);
2559+
25582560
// Look through an implicitly unwrapped optional.
2559-
auto baseTy = cs.getType(base)->getRValueType();
2561+
auto baseTy = cs.getType(base);
25602562
if (auto objTy = cs.lookThroughImplicitlyUnwrappedOptionalType(baseTy)){
25612563
base = coerceImplicitlyUnwrappedOptionalToValue(base, objTy,
25622564
cs.getConstraintLocator(base));
2563-
2564-
baseTy = cs.getType(base)->getRValueType();
2565+
baseTy = objTy;
25652566
}
25662567

25672568
auto &tc = cs.getTypeChecker();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %build-silgen-test-overlays
3+
// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) -Xllvm -sil-full-demangle -emit-silgen %s -enable-sil-ownership
4+
5+
// REQUIRES: objc_interop
6+
7+
import Foundation
8+
9+
extension NSString {
10+
var x: Float { return 0.0 }
11+
}
12+
13+
// note: this has to be a var
14+
var str: String = "hello world"
15+
16+
// Crash when NSString member is accessed on a String with an lvalue base
17+
_ = str.x

0 commit comments

Comments
 (0)