Skip to content

[CSSimplify] Tuple splat should account for single dependent member p… #22960

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
Feb 28, 2019
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
8 changes: 4 additions & 4 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,11 +1085,11 @@ static bool isSingleTupleParam(ASTContext &ctx,
if (!ctx.isSwiftVersionAtLeast(5))
paramType = paramType->lookThroughAllOptionalTypes();

// Parameter should have a label and be either a tuple tuple type,
// or a type variable which might later be assigned a tuple type,
// e.g. opened generic parameter.
// Parameter should not have a label and be either a tuple,
// type variable or a dependent member, which might later be
// assigned (or resolved to) a tuple type, e.g. opened generic parameter.
return !param.hasLabel() &&
(paramType->is<TupleType>() || paramType->is<TypeVariableType>());
(paramType->is<TupleType>() || paramType->isTypeVariableOrMember());
}

/// Attempt to fix missing arguments by introducing type variables
Expand Down
6 changes: 5 additions & 1 deletion test/Constraints/closures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,12 @@ do {
}

func foo(_ arr: [Int]) {
// FIXME: This behavior related to tuple splat being allowed
// in conversion between a single dependent member
// parameter and empty parameter functions e.g.
// () -> Void `convertable to` (T.V) -> Void.
_ = S(arr, id: \.self_) {
// expected-error@-1 {{contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored}} {{30-30=_ in }}
// expected-error@-1 {{type '_' has no member 'self_'}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think fixing this completely will require not re-typechecking at all. You're replacing the dependent member type with UnresolvedType here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this error is just unrelated :( C.Element is resolved properly to Int later on (on the first solve) so we end up comparing () to Int and failing. I'm trying to think of a way to fix this in salvage mode. Maybe we shouldn't attempt splat at all, and let fixMissingArgument and other fixes do their thing, I'll need to add fixes for extraneous and destructuring first though...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we try both, build a disjunction with splat and without splat and see what fixes each possibility produces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about trying to replace argument with type variable and then add conversion constraint to it with original type, this would act similar to disjunction because potential bindings would get both parameter and argument type.

return 42
}
}
Expand Down
25 changes: 24 additions & 1 deletion test/Constraints/tuple_arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1691,4 +1691,27 @@ _ = x.map { (_: Void) in return () }
do {
func f(_: Int...) {}
let _ = [(1, 2, 3)].map(f) // expected-error {{cannot invoke 'map' with an argument list of type '((Int...) -> ())'}}
}
}

// rdar://problem/48443263 - cannot convert value of type '() -> Void' to expected argument type '(_) -> Void'

protocol P_48443263 {
associatedtype V
}

func rdar48443263() {
func foo<T : P_48443263>(_: T, _: (T.V) -> Void) {}

struct S1 : P_48443263 {
typealias V = Void
}

struct S2: P_48443263 {
typealias V = Int
}

func bar(_ s1: S1, _ s2: S2, _ fn: () -> Void) {
foo(s1, fn) // Ok because s.V is Void
foo(s2, fn) // expected-error {{cannot convert value of type '() -> Void' to expected argument type '(_) -> Void'}}
}
}