Skip to content

Commit

Permalink
Don't allow conversion from inout argument to Any parameter.
Browse files Browse the repository at this point in the history
<rdar://problem/23249098>
  • Loading branch information
cwillmor committed Nov 4, 2015
1 parent 9586337 commit a79c1c9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@ matchCallArguments(ConstraintSystem &cs, TypeMatchKind kind,
// In the empty existential parameter case, we don't need to decompose the
// arguments.
if (paramType->isEmptyExistentialComposition()) {
if (argType->is<InOutType>()) {
return ConstraintSystem::SolutionKind::Error;
}
return ConstraintSystem::SolutionKind::Solved;
}

Expand Down Expand Up @@ -1057,6 +1060,10 @@ ConstraintSystem::SolutionKind
ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
ConstraintKind kind, unsigned flags,
ConstraintLocatorBuilder locator) {
if (type1->is<InOutType>()) {
return SolutionKind::Error;
}

SmallVector<ProtocolDecl *, 4> protocols;
type2->getAnyExistentialTypeProtocols(protocols);

Expand Down
4 changes: 2 additions & 2 deletions test/1_stdlib/PrintDiagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ var stream = ""
print(3, appendNewline: false) // expected-error {{'print(_:appendNewline:)' is unavailable: Please use 'terminator: ""' instead of 'appendNewline: false': 'print((...), terminator: "")'}}
debugPrint(3, appendNewline: false) // expected-error {{'debugPrint(_:appendNewline:)' is unavailable: Please use 'terminator: ""' instead of 'appendNewline: false': 'debugPrint((...), terminator: "")'}}

print(3, &stream)
debugPrint(3, &stream)
print(3, &stream) // expected-error{{'&' used with non-inout argument of type 'Any'}}
debugPrint(3, &stream) // expected-error{{'&' used with non-inout argument of type 'Any'}}
print(3, &stream, appendNewline: false) // expected-error {{cannot pass immutable value as inout argument: implicit conversion from 'String' to 'OutputStreamType' requires a temporary}}
debugPrint(3, &stream, appendNewline: false) // expected-error {{cannot pass immutable value as inout argument: implicit conversion from 'String' to 'OutputStreamType' requires a temporary}}
print(4, quack: 5) // expected-error {{'print' is unavailable: Please wrap your tuple argument in parentheses: 'print((...))'}}
9 changes: 9 additions & 0 deletions test/expr/expressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,15 @@ func inoutTests(inout arr: Int) {

// <rdar://problem/17489894> inout not rejected as operand to assignment operator
&x += y // expected-error {{'&' can only appear immediately in a call argument list}}

// <rdar://problem/23249098>
func takeAny(x: Any) {}
takeAny(&x) // expected-error{{'&' used with non-inout argument of type 'Any'}}
func takeManyAny(x: Any...) {}
takeManyAny(&x) // expected-error{{'&' used with non-inout argument of type '[Any]'}}
takeManyAny(1, &x) // expected-error{{'&' used with non-inout argument of type 'Any'}}
func takeIntAndAny(x: Int, _ y: Any) {}
takeIntAndAny(1, &x) // expected-error{{'&' used with non-inout argument of type 'Any'}}
}


Expand Down

0 comments on commit a79c1c9

Please sign in to comment.