mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[TypeChecker] SE-0347: Enable type inference from default expressions
This commit is contained in:
@@ -752,10 +752,6 @@ namespace swift {
|
||||
/// closures.
|
||||
bool EnableMultiStatementClosureInference = true;
|
||||
|
||||
/// Enable experimental support for generic parameter inference in
|
||||
/// parameter positions from associated default expressions.
|
||||
bool EnableTypeInferenceFromDefaultArguments = false;
|
||||
|
||||
/// See \ref FrontendOptions.PrintFullConvention
|
||||
bool PrintFullConvention = false;
|
||||
};
|
||||
|
||||
@@ -1104,9 +1104,6 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
|
||||
Opts.EnableMultiStatementClosureInference |=
|
||||
Args.hasArg(OPT_experimental_multi_statement_closures);
|
||||
|
||||
Opts.EnableTypeInferenceFromDefaultArguments |=
|
||||
Args.hasArg(OPT_experimental_type_inference_from_defaults);
|
||||
|
||||
Opts.PrintFullConvention |=
|
||||
Args.hasArg(OPT_experimental_print_full_convention);
|
||||
|
||||
|
||||
@@ -1780,7 +1780,8 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
|
||||
if (parameterBindings[paramIdx].empty() && callee) {
|
||||
auto &ctx = cs.getASTContext();
|
||||
|
||||
if (ctx.TypeCheckerOpts.EnableTypeInferenceFromDefaultArguments) {
|
||||
// Type inference from default value expressions.
|
||||
{
|
||||
auto *paramList = getParameterList(callee);
|
||||
if (!paramList)
|
||||
continue;
|
||||
|
||||
@@ -464,10 +464,6 @@ Type TypeChecker::typeCheckParameterDefault(Expr *&defaultValue,
|
||||
return defaultValue->getType();
|
||||
}
|
||||
|
||||
// If inference is disabled, fail.
|
||||
if (!ctx.TypeCheckerOpts.EnableTypeInferenceFromDefaultArguments)
|
||||
return Type();
|
||||
|
||||
// Caller-side defaults are always type-checked based on the concrete
|
||||
// type of the argument deduced at a particular call site.
|
||||
if (isa<MagicIdentifierLiteralExpr>(defaultValue))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/InferViaDefaults.swiftmodule -enable-experimental-type-inference-from-defaults -module-name InferViaDefaults %S/Inputs/type_inference_via_defaults_other_module.swift
|
||||
// RUN: %target-swift-frontend -enable-experimental-type-inference-from-defaults -module-name main -typecheck -verify -I %t %s %S/Inputs/type_inference_via_defaults_other_module.swift
|
||||
// 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
|
||||
|
||||
func testInferFromResult<T>(_: T = 42) -> T { fatalError() } // Ok
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/InferViaDefaults.swiftmodule -enable-experimental-type-inference-from-defaults -module-name InferViaDefaults %S/Inputs/type_inference_via_defaults_other_module.swift
|
||||
// RUN: %target-build-swift -module-name main -Xfrontend -enable-experimental-type-inference-from-defaults -parse-as-library -I %t %s %S/Inputs/type_inference_via_defaults_other_module.swift -o %t/a.out
|
||||
// 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-build-swift -module-name main -Xfrontend -parse-as-library -I %t %s %S/Inputs/type_inference_via_defaults_other_module.swift -o %t/a.out
|
||||
// RUN: %target-run %t/a.out | %FileCheck %s --color
|
||||
|
||||
// REQUIRES: OS=macosx && CPU=x86_64
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// RUN: %target-typecheck-verify-swift
|
||||
// RUN: %target-typecheck-verify-swift -enable-experimental-type-inference-from-defaults
|
||||
|
||||
var t1a: (Int...) = (1)
|
||||
// expected-error@-1 {{cannot create a variadic tuple}}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// RUN: %target-typecheck-verify-swift
|
||||
// RUN: %target-typecheck-verify-swift -enable-experimental-type-inference-from-defaults
|
||||
|
||||
func takeIntToInt(_ f: (Int) -> Int) { }
|
||||
func takeIntIntToInt(_ f: (Int, Int) -> Int) { }
|
||||
|
||||
Reference in New Issue
Block a user