Commit Graph

46 Commits

Author SHA1 Message Date
Alex Hoppen
66104395d7 [Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
Some editors use diagnostics from SourceKit to replace build issues. This causes issues if the diagnostics from SourceKit are formatted differently than the build issues. Make sure they are rendered the same way, removing most uses of `DiagnosticsEditorMode`.

To do so, always emit the `add stubs for conformance` note (which previously was only emitted in editor mode) and remove all `; add <something>` suffixes from notes that state which requirements are missing.

rdar://129283608
2024-08-07 14:01:30 -07:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Doug Gregor
46f3ba6968 [Effects] Ensure that we use the original parameter type when determining rethrows
Rethrows checking is based on the interface type of the parameter, with
substitutions applied only when we need to figure out the thrown error
type. Fixes a regression caused by my attempt at dealing with parameter
packs in rethrows functions.
2023-11-15 09:45:24 -08:00
Doug Gregor
ae1c0232c7 Fix effects checking for rethrowing functions involving parameter packs
Effects checking for rethrowing functions was using unsubstituted
interface types for the parameter list. When a rethrows function has
parameter pack arguments, the interface type may have a different
number of parameters from the resulting argument list, causing the
effects checking to bail out early.

This has been wrong since the introduction of parameter packs, but
recent refactoring of effects checking ended up promoting this bug to
a compiler crash. Fix the bug, and make sure we don't crash if the
effects checker hits an issue here.

Fixes rdar://116740385.
2023-11-14 14:28:48 -08:00
Holly Borla
06486f627c [NFC] Add a test case for missing 'try' diagnostics with existential opening. 2022-10-25 19:57:51 -07:00
Anthony Latsis
edd4010664 Gardening: Migrate test suite to GH issues: decl/func 2022-08-26 03:26:32 +03:00
Kavon Farvardin
be9890815a update existing regression tests after small diagnostics refactor
new phrasing in the error messages to match up with
other phrasing used in messages.
2021-04-15 10:08:58 -07:00
Slava Pestov
f1831fb16a Sema: Teach rethrows checking about 'nil' default arguments
In Swift 5.4, this worked:

  func foo(_: (() throws -> ())? = nil) rethrows {}
  foo()  // no 'try' needed

However, this was an accident, because this was also accepted:

  func foo(_: (() throws -> ())? = { throw ... }) rethrows {}
  foo()  // 'try' *should* be required here

This got fixed at some point recently, but since people rely on the
old case working for 'nil', let's add back a check for a 'nil'
default parameter.

Fixes rdar://problem/76169080.
2021-04-02 23:56:59 -04:00
Kenneth Chew
289840b42d Add test case for diagnostic 'because_rethrows_default_argument_throws'
The first test case added ideally shouldn't have any expected error or diagnostic.
However, due to SR-1534, there is an error emitted here. Thus, an expected error is
used here to show the compiler's behavior today.

If SR-1534 is fixed in the future, the first test case should no longer have any
expected error nor an expected note. However, the second test case should still be
left alone.

Addresses SR-14270
2021-03-17 13:39:22 -04:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Pavel Yaskevich
43670cb897 [TypeChecker] Classify nil literal and .none as non-contriburing to throws
Original fix for SR-9102 stripped throws bit from the function types
nested inside optionals before attempting bindings, that doesn't
work with e.g. default parameter values because conversions from
throwing and non-throwing functions are only allowed in subtype
relationship but function types nested inside optionals are going
to be equated.

So this patch takes an alternative approach and attempts to pattern
match `nil` literal and `.none` use and classify argument as
non-contributing to throws.

Resolves: rdar://problem/47550715
2019-01-29 10:27:37 -08:00
Slava Pestov
1b27618e3e Sema: Teach rethrows checking about OtherConstructorDeclRefExpr
Fixes <https://bugs.swift.org/browse/SR-8788>.
2019-01-18 00:35:03 -05:00
Mark Lacey
edfe4ebb54 Add a test for SR-6299.
This was fixed a while ago.
2018-07-26 10:33:31 -07:00
Mark Lacey
5fce236ba9 [Sema] Fix a crash in rethrows checking.
We were assuming that variadic parameters are at the end, so we didn't
fill in all the types of the tuple elements in the tuple type we were
constructing.
2018-05-30 15:23:27 -07:00
Slava Pestov
58d3c102e2 Sema: Handle capture lists in 'rethrows' checking
Fixes <https://bugs.swift.org/browse/SR-7120> and
<rdar://problem/38142105>.
2018-05-10 14:02:16 -07:00
Pavel Yaskevich
b7ab7491e6 [QoI] Provide fix-it for missing "try" when calling throwing function
When calling a throwing function without 'try', let's suggest multiple
possibilities of note + fix-it for user to choose from.

Resolves: rdar://problem/33040113
2017-07-09 19:22:43 -07:00
Doug Gregor
dd96aee1b1 [Type checker] Fix rethrow checking with a single argument label harder.
My original fix for rdar://problem/31794932 didn't work for generic
functions because it was checking in the unsubstituted interface
type. Check structurally instead. Fixes rdar://problem/31794932.
2017-04-25 12:37:32 -07:00
Doug Gregor
b07d9951e4 [Type checker] Handle 'rethrows' checks for single-parameter functions.
The throw-checking code wasn't properly coping with functions that
take a single, labeled argument, due to the longstanding lie that
pretends that functions take a tuple argument vs. zero or more
separate arguments. Here, the lie manifests as spurious "call can
throw, but is not marked as such" errors.

Fixes rdar://problem/31794932.
2017-04-24 14:48:54 -07:00
Joe Groff
e9544bae0a Sema: Look through DotSyntaxBaseIgnored when finding function DeclRefs for rethrows checking.
Fixes rdar://problem/30618853.
2017-02-24 16:04:47 -08:00
Rintaro Ishizaki
e4c18ba9ba [Parse] Add fix-it for 'rethrows' in function type 2016-11-30 23:09:38 +09:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Michael Ilseman
f48471ebd4 [noescape by default] purge tests of needless @noescape 2016-08-04 16:14:27 -07:00
Robert Widmann
4f465224ea Polish off uses of dynamicType in tests 2016-07-29 16:59:14 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
Trent Nadeau
0cc851568a Updated tests to use @discardableResult and _ = . 2016-05-11 22:53:38 -04:00
Chris Lattner
8746676616 Move @noescape and @autoclosure to their new places in various tests, NFC. 2016-04-15 16:05:35 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Alex Hoppen
3f115d4e12 [Sema] SR-317: Allow rethrowing functions to take an optional function parameter 2016-03-11 13:22:54 +01:00
Max Moiseev
cf4bafe9e3 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-03 13:22:03 -08:00
Kevin Ballard
88a45b6bd0 [Sema][SR-681] Allow catch blocks to rethrow errors when safe
A catch block can only be entered if the do block threw an error. In a
rethrows function, if the do block throws an error only under rethrows
conditions, then the catch block can only be entered under rethrows
conditions, which means the catch block can unconditionally throw and
it's still safe.

This enables code that looks like

```swift
func foo(f: () throws -> Void) rethrows {
    do {
        try f()
    } catch is SomeError {
        throw OtherError()
    }
}
```
2016-02-26 23:19:13 -08:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -08:00
Chris Willmore
983a674e0c Make use of curried function declaration syntax an error.
<rdar://problem/23111018>
2016-01-20 21:57:38 -08:00
Doug Gregor
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Chris Lattner
a8deb14ce0 add comment with radar title 2016-01-16 23:18:06 -08:00
Chris Lattner
20263bf466 fix <rdar://problem/24221830> Bogus "no calls to throwing functions" warning in derived throwing init
This is a case where we used to produce:

<unknown>:0: warning: no calls to throwing functions occur within 'try' expression

Which is bogus, due to the try expr implicitly generated as part of the
implicit super.init call for an init that doesn't otherwise contain a super.init.
Silence this warning by ignoring implicitly generated trys, since this try gets
produced before name binding has resolved exactly which try is being invoked.
2016-01-16 23:15:47 -08:00
Max Moiseev
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
ken0nek
3ac60b13f5 Add spaces before and after closure arrow in test 2015-12-23 04:38:46 +09:00
Dmitri Gribenko
feacbc4433 Rename ErrorType to ErrorProtocol 2015-12-09 17:12:19 -08:00
Chris Willmore
30af42fda9 Add warning that curried function decl syntax is going away.
<rdar://problem/23111018>
2015-11-02 15:45:11 -08:00
Jordan Rose
4c82fe3394 Tweak diagnostic text for 'rethrows'-related mistakes.
The first two are now more in line with the messages you get for
non-'rethrows' functions.

rdar://problem/21654534

Swift SVN r30558
2015-07-24 02:45:11 +00:00
Joe Pamer
2d86296827 When converting a closure's function type to a non-escaping function type, only propagate the 'throws' ExtInfo bit if necessary. (rdar://problem/21881995)
Swift SVN r30556
2015-07-23 23:35:42 +00:00
John McCall
7a5ffeddf4 Implement 'rethrows' checking in Sema.
Now with amazing new fixes and tests for methods and generics!

Swift SVN r28499
2015-05-13 00:03:09 +00:00
Ted Kremenek
07251be929 Revert "Implement 'rethrows' checking in Sema."
This was asserting in the performance suite.

Swift SVN r28491
2015-05-12 22:37:20 +00:00
John McCall
3e4bcab7fb Implement 'rethrows' checking in Sema.
Swift SVN r28488
2015-05-12 22:10:41 +00:00
John McCall
fdcecfcfb7 Move error-handling diagnostics to Sema and check try coverage.
Needs better test-case coverage.

Swift SVN r27898
2015-04-29 00:49:40 +00:00
John McCall
3d3f1a7d7e Parsing/AST/Sema support for rethrows, and fix bugs with
throws/rethrows override and conformance checking.

Swift SVN r27508
2015-04-20 23:39:12 +00:00