Skip to content

Commit c74b7a5

Browse files
authored
Merge pull request #82617 from hamishknight/solve-escape-6.2
[6.2] [CS] Fix a couple of use-after-frees
2 parents 8db1ad6 + f72c443 commit c74b7a5

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Solution::computeSubstitutions(NullablePtr<ValueDecl> decl,
116116
} else if (!type->is<PackType>())
117117
type = PackType::getSingletonPackExpansion(type);
118118
}
119-
replacementTypes.push_back(type);
119+
replacementTypes.push_back(simplifyType(type));
120120
}
121121

122122
auto lookupConformanceFn =
@@ -145,9 +145,9 @@ Solution::computeSubstitutions(NullablePtr<ValueDecl> decl,
145145
return conformance;
146146
};
147147

148-
return SubstitutionMap::get(sig,
149-
replacementTypes,
150-
lookupConformanceFn);
148+
auto subs = SubstitutionMap::get(sig, replacementTypes, lookupConformanceFn);
149+
CONDITIONAL_ASSERT(!subs.getRecursiveProperties().isSolverAllocated());
150+
return subs;
151151
}
152152

153153
// Lazily instantiate function definitions for class template specializations.

lib/Sema/CSDiagnostics.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3880,7 +3880,8 @@ bool NonOptionalUnwrapFailure::diagnoseAsError() {
38803880
diagnostic = diag::invalid_force_unwrap;
38813881

38823882
auto range = getSourceRange();
3883-
emitDiagnostic(diagnostic, BaseType).highlight(range).fixItRemove(range.End);
3883+
emitDiagnostic(diagnostic, resolveType(BaseType))
3884+
.highlight(range).fixItRemove(range.End);
38843885
return true;
38853886
}
38863887

test/Constraints/rdar154553285.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %target-typecheck-verify-swift -disable-experimental-parser-round-trip
2+
3+
// Make sure we don't crash
4+
func testInvalidInInterpolation(_ x: Int) {
5+
_ = "\((x, \[]))" // expected-error {{invalid component of Swift key path}}
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// {"signature":"swift::ProtocolConformanceRef::forAbstract(swift::Type, swift::ProtocolDecl*)"}
2+
// RUN: not %target-swift-frontend -typecheck %s
3+
var sixDoubles
4+
: Double "six has the value [\( ( sixDoubles \[]) }0 \0\0 \0 \sixDoubles)"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// {"signature":"swift::FunctionType::get(llvm::ArrayRef<swift::AnyFunctionType::Param>, swift::Type, std::__1::optional<swift::ASTExtInfo>)"}
2+
// RUN: not %target-swift-frontend -typecheck %s
3+
struct a < b : FixedWidthInteger extension a : Sequence {
4+
c {
5+
{ for
6+
d self { b(truncatingIfNeeded : d
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// {"signature":"swift::TypeBase::computeCanonicalType()"}
2+
// RUN: not %target-swift-frontend -typecheck %s
3+
func a (Int -> Int = { $0 func b( () = {}? ) func b {
4+
/ 1

0 commit comments

Comments
 (0)