Skip to content

[AST] Preserve l-valueness of covariant result type after replacement #34673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2020
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
9 changes: 6 additions & 3 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,13 +809,16 @@ Type TypeBase::getWithoutParens() {
Type TypeBase::replaceCovariantResultType(Type newResultType,
unsigned uncurryLevel) {
if (uncurryLevel == 0) {
if (auto objectType = getOptionalObjectType()) {
bool isLValue = is<LValueType>();

auto loadedTy = getWithoutSpecifierType();
if (auto objectType = loadedTy->getOptionalObjectType()) {
assert(!newResultType->getOptionalObjectType());
return OptionalType::get(
newResultType = OptionalType::get(
objectType->replaceCovariantResultType(newResultType, uncurryLevel));
}

return newResultType;
return isLValue ? LValueType::get(newResultType) : newResultType;
}

// Determine the input and result types of this function.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: not %target-swift-frontend %s -typecheck

final class Whatever {
static var instance: Self!

static var shared: Self {
return instance ?? {
instance = Self()
return instance
}
}
}