Skip to content

Commit e5b9ad7

Browse files
committed
[Type checker] Don't overflow array bounds with #fileLiteral *ahem*.
Fixes rdar://problem/26586984.
1 parent d225a21 commit e5b9ad7

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ getAlternativeLiteralTypes(KnownProtocolKind kind) {
249249
case KnownProtocolKind::ExpressibleByImageLiteral: index = 11; break;
250250
case KnownProtocolKind::ExpressibleByFileReferenceLiteral: index = 12; break;
251251
}
252+
static_assert(NumAlternativeLiteralTypes == 13, "Wrong # of literal types");
252253

253254
// If we already looked for alternative literal types, return those results.
254255
if (AlternativeLiteralTypes[index])

lib/Sema/ConstraintSystem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,8 @@ class ConstraintSystem {
925925
MemberLookups;
926926

927927
/// Cached sets of "alternative" literal types.
928-
Optional<ArrayRef<Type>> AlternativeLiteralTypes[12];
928+
static const unsigned NumAlternativeLiteralTypes = 13;
929+
Optional<ArrayRef<Type>> AlternativeLiteralTypes[NumAlternativeLiteralTypes];
929930

930931
/// \brief Folding set containing all of the locators used in this
931932
/// constraint system.

test/Sema/object_literals_osx.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ struct Path: _ExpressibleByFileReferenceLiteral {
2222

2323
let p1: Path = #fileLiteral(resourceName: "what.txt")
2424
let p2 = #fileLiteral(resourceName: "what.txt") // expected-error{{could not infer type of file reference literal}} expected-note{{import Foundation to use 'URL' as the default file reference literal type}}
25+
26+
let text = #fileLiteral(resourceName: "TextFile.txt").relativeString! // expected-error{{type of expression is ambiguous without more context}}

0 commit comments

Comments
 (0)