Skip to content

Commit b490f8a

Browse files
committed
[CSApply] Always try to load arguments constructing object literals
AST rewriter needs to make sure that all of the arguments are loaded since it's currently possible to pass l-value type as an argument to object literal (`#{file, color, image}Literal`). Resolves: rdar://problem/62927467 (cherry picked from commit baaff0d)
1 parent c93c434 commit b490f8a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,6 +2643,7 @@ namespace {
26432643
if (!witness || !isa<AbstractFunctionDecl>(witness.getDecl()))
26442644
return nullptr;
26452645
expr->setInitializer(witness);
2646+
expr->setArg(cs.coerceToRValue(expr->getArg()));
26462647
return expr;
26472648
}
26482649

test/Sema/object_literals_osx.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,13 @@ let text = #fileLiteral(resourceName: "TextFile.txt").relativeString! // expecte
2727

2828
// rdar://problem/49861813
2929
#fileLiteral() // expected-error{{missing argument for parameter 'resourceName' in call}} expected-error{{could not infer type of file reference literal}} expected-note{{import Foundation to use 'URL' as the default file reference literal type}}
30+
31+
// rdar://problem/62927467
32+
func test_literal_arguments_are_loaded() {
33+
var resource = "foo.txt" // expected-warning {{variable 'resource' was never mutated; consider changing to 'let' constant}}
34+
let _: Path = #fileLiteral(resourceName: resource) // Ok
35+
36+
func test(red: inout Float, green: inout Float) -> S {
37+
return #colorLiteral(red: red, green: green, blue: 1, alpha: 1) // Ok
38+
}
39+
}

0 commit comments

Comments
 (0)