Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,21 @@ ConstraintSystem::getTypeOfMemberReference(
OpenedTypeMap *replacementsPtr) {
// Figure out the instance type used for the base.
Type baseObjTy = getFixedTypeRecursive(baseTy, /*wantRValue=*/true);

ParameterTypeFlags baseFlags;
// FIXME(diagnostics): `InOutType` could appear here as a result
// of successful re-typecheck of the one of the sub-expressions e.g.
// `let _: Int = { (s: inout S) in s.bar() }`. On the first
// attempt to type-check whole expression `s.bar()` - is going
// to have a base which points directly to declaration of `S`.
// But when diagnostics attempts to type-check `s.bar()` standalone
// its base would be tranformed into `InOutExpr -> DeclRefExr`,
// and `InOutType` is going to be recorded in constraint system.
if (auto objType = baseObjTy->getInOutObjectType()) {
baseObjTy = objType;
baseFlags = baseFlags.withInOut(true);
}

bool isInstance = true;
if (auto baseMeta = baseObjTy->getAs<AnyMetatypeType>()) {
baseObjTy = baseMeta->getInstanceType();
Expand All @@ -1200,7 +1215,7 @@ ConstraintSystem::getTypeOfMemberReference(
return getTypeOfReference(value, functionRefKind, locator, useDC, base);
}

FunctionType::Param baseObjParam(baseObjTy);
FunctionType::Param baseObjParam(baseObjTy, Identifier(), baseFlags);

// Don't open existentials when accessing typealias members of
// protocols.
Expand Down
9 changes: 9 additions & 0 deletions test/Constraints/closures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -849,3 +849,12 @@ func rdar_45659733() {
}
}
}

func rdar45771997() {
struct S {
mutating func foo() {}
}

let _: Int = { (s: inout S) in s.foo() }
// expected-error@-1 {{cannot convert value of type '(inout S) -> ()' to specified type 'Int'}}
}