Skip to content

[AST] SE-0347: Don't check default expression status in type request #60109

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 2 commits into from
Jul 19, 2022
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
5 changes: 1 addition & 4 deletions lib/AST/TypeCheckRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1214,10 +1214,7 @@ Optional<Type> DefaultArgumentTypeRequest::getCachedResult() const {
if (!defaultInfo)
return None;

if (!defaultInfo->InitContextAndIsTypeChecked.getInt())
return None;

return defaultInfo->ExprType;
return defaultInfo->ExprType ? defaultInfo->ExprType : Optional<Type>();
}

void DefaultArgumentTypeRequest::cacheResult(Type type) const {
Expand Down
10 changes: 6 additions & 4 deletions test/Constraints/type_inference_from_default_exprs.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/InferViaDefaults.swiftmodule -module-name InferViaDefaults %S/Inputs/type_inference_via_defaults_other_module.swift
// RUN: %target-swift-frontend -module-name main -typecheck -verify -I %t %s %S/Inputs/type_inference_via_defaults_other_module.swift
// RUN: %target-build-swift -parse-as-library -emit-library -emit-module-path %t/InferViaDefaults.swiftmodule -module-name InferViaDefaults %S/Inputs/type_inference_via_defaults_other_module.swift -o %t/%target-library-name(InferViaDefaults)
// RUN: %target-swift-frontend -typecheck -verify -lInferViaDefaults -module-name main -I %t -L %t %s

import InferViaDefaults

func testInferFromResult<T>(_: T = 42) -> T { fatalError() } // Ok

Expand Down Expand Up @@ -136,8 +138,8 @@ func main() {
testMultiple(a: 0.0, b: "a") // Ok

// From a different module
with_defaults() // Ok
with_defaults("") // Ok
InferViaDefaults.with_defaults() // Ok
InferViaDefaults.with_defaults("") // Ok

_ = S()[] // Ok
_ = S()[B()] // Ok
Expand Down