Skip to content
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

[Diagnostics] Fixits for extra arguments in nullary call #16652

Closed

Conversation

AnthonyLatsis
Copy link
Collaborator

https://bugs.swift.org/browse/SR-7624

@xedin
PR aside, there is something very strange going on in the tests here. Please look into the review.
The issue is probably somehow related to #14477

@@ -1666,7 +1666,7 @@ do {
f(a: logNoOptional() as ((()) -> Void)) // expected-error {{cannot convert value of type '(()) -> Void' to expected argument type '(() -> Void)?'}}

func g() {}
g(()) // expected-error {{argument passed to call that takes no arguments}}
g(()) // expected-error {{argument passed to call that takes no arguments}} {{5-7=}}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Over here, the error is raised and the test passes.

@@ -95,6 +95,16 @@ func parenPatternInArg((a): Int) -> Int { // expected-error {{expected parameter
}
parenPatternInArg(0) // expected-error {{argument passed to call that takes no arguments}}

func nullaryFunctionFixit() {}
nullaryFunctionFixit(())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here, however, the same error has to be raised, but it doesn't happen. When I run the compiler, it does raise an error. When I run the test, it passes without expecting any error.

@@ -428,7 +428,7 @@ let _: (Int) -> (Int, Color) = { ($0, .Unknown("")) } // expected-error {{missin
let _: Color = .Unknown("") // expected-error {{missing argument label 'description:' in call}} {{25-25=description: }}
let _: Color = .Unknown // expected-error {{member 'Unknown' expects argument of type '(description: String)'}}
let _: Color = .Unknown(42) // expected-error {{missing argument label 'description:' in call}}
let _ : Color = .rainbow(42) // expected-error {{argument passed to call that takes no arguments}}
let _ : Color = .rainbow(42) // expected-error {{argument passed to call that takes no arguments}} {{26-28=}}
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, but IMO, we should not remove users code like this. This might be just a mistype of function name.
Removing () is implemented in #9583 because of migration need and it probably reflects users intent.

Copy link
Member

@xedin xedin left a comment

Choose a reason for hiding this comment

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

The reason why this logic is here and why some tests fail and some don't is because type-checker has different logic when it comes to parens in the arguments positions based on the compiler version e.g. test/Constraints/tuple_arguments.swift specifies 5 and test/decl/func/functions.swift defaults to 3 i believe. We are currently trying to come up with a better representation for the arguments/parameters in function types, before that lands I'm not sure it's worth making any changes to this.

@AnthonyLatsis
Copy link
Collaborator Author

Thanks for the explanation, I had a second thought about that but wasn't sure. I am glad we no longer support the f() === f(()) === f((())) ... behavior in swift 5 and I agree with @rintaro. It was a good experience, nevertheless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants