Skip to content

Commit 1dec944

Browse files
committed
[SourceKit] Don't report type for InjectIntoOptionalExpr
Fixes incorrectly reporting an optional type for an expression when the contextual type is optional. fixes #66882 rdar://111462279
1 parent 964a51f commit 1dec944

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/IDE/IDETypeChecking.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,10 @@ class ExpressionTypeCollector: public SourceEntityWalker {
667667
if (E->getType().isNull())
668668
return false;
669669

670+
// We should not report a type for InjectIntoOptionalExpr
671+
if (isa<InjectIntoOptionalExpr>(E))
672+
return false;
673+
670674
// If we have already reported types for this source range, we shouldn't
671675
// report again. This makes sure we always report the outtermost type of
672676
// several overlapping expressions.

test/SourceKit/ExpressionType/basic.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ func DictS(_ a: [Int: S]) {
2020
_ = a[2]?.val.advanced(by: 1).byteSwapped
2121
}
2222

23+
func optExpr(str: String?) -> String? {
24+
let a: String? = str
25+
let b: String? = "Hey"
26+
let c: String = "Bye"
27+
return c
28+
}
29+
2330
// RUN: %sourcekitd-test -req=collect-type %s -- %s | %FileCheck %s
2431
// CHECK: (183, 202): Int
2532
// CHECK: (183, 196): String
@@ -31,3 +38,6 @@ func DictS(_ a: [Int: S]) {
3138
// CHECK: (291, 292): Int?
3239
// CHECK: (295, 332): Int?
3340
// CHECK: (295, 320): Int
41+
// CHECK: (395, 398): String?
42+
// CHECK: (418, 423): String
43+
// CHECK: (457, 458): String

0 commit comments

Comments
 (0)