Skip to content

[ConstraintSystem] [NFC] add tests for label matching diagnostics #31934

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
May 24, 2020

Conversation

omochi
Copy link
Contributor

@omochi omochi commented May 21, 2020

This patch add test cases for label matching diagnostics.

This haven't changes for compiler.

This is a part of following my other project.
#30444

I am planning to make many changes of diagnostics there particular corner cases.
It is useful to bake current behavior to repository as test cases
before reviewing my that project.

@omochi omochi requested a review from xedin May 21, 2020 08:16
@omochi
Copy link
Contributor Author

omochi commented May 21, 2020

@swift-ci please smoke test

@@ -1415,6 +1415,107 @@ let f12: (Int) -> Void = { _ in }
func f12<T : P2>(_ n: T, _ f: @escaping (T) -> T) {}
f12(3, f4)// expected-error {{extra argument in call}}

func testLabelErrorsBasic() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if since there are quite a few tests specifically about label matching, is it a good idea to separate them in their own label matching file? This is just an idea because I see this diagnostics file is general, and maybe separate label matching diagnostics can make it easier to organize things :)

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 think it's a good idea.

Test cases about matching of call arguments are also in test/Constraints/keyword_arguments.swift.

I don't know how other authors distinguish them.

I choice diagnostics.swift for what has interest in unlabeled arguments because they has no keyword.

If we can make a big change,
I want to rename keyword_arguments.swift to argument_matching.swift and
move some cases in diagnostics.swift to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we can, I want to split it more like:

  • argument_matching_labeled.swift
  • argument_matching_unlabeled.swift
  • argument_matching_variadic.swift
  • argument_matching_defaulted.swift
  • argument_matching_trailing_closure.swift

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 since all fall in the context of argument_matching I think only one file is already fine.
I don't know exactly what are the rules to this in the test suit, but to me, it seems reasonable to separate in, for example, an argument_matching.swift and have the subcases e.g. labeled, unlabeled, variadic.. divided inside the file.

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 extracting all this into test/Constraints/argument_matching.swift would be just fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@LucianoPAlmeida @xedin Thanks to comment.
OK I will make new patch to create argument_matching.swift.

@@ -6,8 +6,11 @@ struct S: _ExpressibleByColorLiteral {
}

let y: S = #colorLiteral(red: 1, green: 0, blue: 0, alpha: 1)
let y2 = #colorLiteral(red: 1, green: 0, blue: 0, alpha: 1) // expected-error{{could not infer type of color literal}} expected-note{{import AppKit to use 'NSColor' as the default color literal type}}
let y3 = #colorLiteral(red: 1, bleen: 0, grue: 0, alpha: 1) // expected-error{{incorrect argument labels in call (have 'red:bleen:grue:alpha:', expected 'red:green:blue:alpha:')}} expected-error{{could not infer type of color literal}} expected-note{{import AppKit to use 'NSColor' as the default color literal type}}
let y2 = #colorLiteral(red: 1, green: 0, blue: 0, alpha: 1) // expected-error{{could not infer type of color literal}}
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 we should keep it as is since this changes is unrelated to other tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK.
I will move it to new another patch.

@omochi
Copy link
Contributor Author

omochi commented May 22, 2020

I will make two new other patches.

  • (1) I make argument_matching.swift by renamed from keyword_arguments.swift.
    And move labeling cases in diagnostics.swift to it.

  • (2) I break lines expectation in object_lierals_osx.swift.

After these works will be finished, I will adjust this patch to make it only add new tests.

@xedin
Copy link
Contributor

xedin commented May 22, 2020

Sounds like a plan!

It bakes current behavior for reviewing changes in future.
@omochi
Copy link
Contributor Author

omochi commented May 23, 2020

@LucianoPAlmeida @xedin I moved test cases to argument_matching.swift.

@swift-ci please smoke test

f(aa: 0, 1, cc: 2, dd: 3, ee: 4, ff: 5)
// expected-error@-1 {{extraneous argument label 'aa:' in call}} {{5-9=}} {{none}}

// 1 ooo
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question, what is 'ooo'?

Copy link
Contributor

Choose a reason for hiding this comment

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

out of order

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, thanks :)

@LucianoPAlmeida
Copy link
Contributor

LGTM! @omochi :)

@omochi omochi requested a review from xedin May 24, 2020 00:24
@xedin xedin merged commit d3162e4 into swiftlang:master May 24, 2020
@omochi omochi deleted the test-labels branch May 24, 2020 05:19
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.

3 participants