Commit Graph

144 Commits

Author SHA1 Message Date
Mykola Pokhylets
4aa2847ad6 Fixed some tests
Remaining failures:

DebugInfo/guard-let-scope4.swift
expr/closure/closures.swift
SILGen/capture-transitive.swift
SILGen/dynamic_self.swift
SILGen/unowned-class-bound-generic-parameter.swift
2025-05-19 09:37:03 +02:00
Jamie
6c676c9f22 [AST][SILOptimizer]: unify missing return diagnostics in some cases
Previously, missing return diagnostics for unreachable subscripts
differed from the treatment unreachable functions received, leading to
inconsistent diagnostic behavior. This change removes the responsibility
for handling the relevant diagnostics from the AST code, in favor of the
diagnostics implemented via the SIL optimizer. Additionally, where the
AST-generation code would previously have diagnosed a missing return for
an implicit empty getter, it will now admit as valid, deferring the
missing return diagnostics to the later SIL passes.
2024-08-07 08:14:11 -05:00
Joe Groff
b4f536927a Disable destructuring initializations in struct let stored properties.
This looks like it was never properly implemented, since when we generate the
memberwise initializer for the struct in SILGen, it incorrectly tries to apply
the entire initializer expression to each variable binding in the pattern,
rather than destructuring the result and pattern-matching it to the variables.
Since it never worked it doesn't look like anyone is using this, so let's
put up an error saying it's unsupported until we can implement it properly.
Add `StructLetDestructuring` as an experimental feature flag so that tests around
the feature for things like module interface printing can still work.
2023-10-03 13:24:39 -07:00
Anthony Latsis
97e122fee7 Gardening: Migrate test suite to GH issues: decl/var 2022-08-26 04:09:10 +03:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
LucianoAlmeida
29879ea822 [Parser] Improving wording for invalid empty computed properties and subscripts 2022-01-04 23:46:09 -03:00
LucianoAlmeida
8581d1da42 [Sema] Avoid misleading diagnostics for incomplete enum computed properties 2022-01-04 23:46:09 -03:00
Matt Diephouse
29a04d4cc4 [Diags] Don't error twice for incomplete computed properties in extensions
If you have an empty computed property in an extension:

```swift
struct S {}

extension S {
    var foo: Int {
    }
}
```

Then Swift will give 2 conflicting errors: one that calls it a computed
property and another that calls it a stored property.

```
5:5: error: computed property must have accessors specified
    }
    ^
4:9: error: extensions must not contain stored properties
    var foo: Int {
        ^
```

This removes the unhelpful second diagnostic by adding a getter to the
property when the first diagnostic is in an extension.

This happens to me frequently. I'll decide to add a computed property,
write its declaration, then pause to decide how to implement it. The
presence of a 2nd error is both distracting and confusing.
2020-05-02 14:24:39 -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
Slava Pestov
2c2d087242 Sema: More accurate VarDeclUsageChecker analysis with local functions
We used to take all the captures of a local function and treat them all
as read and write usages of vars from an outer scope. Instead, let's
refactor the analysis to walk into local functions.
2020-04-03 18:07:08 -04:00
Hassan El Desouky
d0b6d9f2c1 Improve diagnostic for read-only properties
Make the message within 80 columns width
Improve diagnostic for read-only properties
Improve diagnostic for read-only properties
Improve diagnostic for read-only properties
2020-03-09 04:48:54 +02:00
Slava Pestov
1df3d1a33c Frontend: Don't interleave parsing and typechecking for the main file
SIL files still require this behavior; if we cleaned that up we
could simplify a fair bit of code here.

Fixes <https://bugs.swift.org/browse/SR-284>,
<https://bugs.swift.org/browse/SR-4426>.
2019-12-05 08:45:55 -05:00
Jesse Rusak
f5f214de21 Improve warning for inferring an undesirable type (#27797)
* [Sema][Diagnostics] Add fixit for warning when inferring an undesirable type

* [Sema][Diagnostics] Generalize undesirable type warning to include arrays of empty tuples

https://bugs.swift.org/browse/SR-11511
2019-11-10 01:56:58 +00:00
Slava Pestov
2ef101c815 Sema: Don't add local functions to TC.definedFunctions
Instead, check them and their error handling right away.

In addition to fixing the crash in the radar, this also causes
us to emit unused variable warnings in functions containing
local functions.

Eventually, TC.definedFunctions should go away altogether.

Fixes <rdar://problem/53956342>.
2019-08-07 00:37:21 -04:00
Slava Pestov
1ee2db4520 AST: Accessors no longer appear as members of their parent DeclContext
Accessors logically belong to their storage and can be synthesized
on the fly, so removing them from the members list eliminates one
source of mutability (but doesn't eliminate it; there are also
witnesses for derived conformances, and implicit constructors).

Since a few ASTWalker implementations break in non-trivial ways when
the traversal is changed to visit accessors as children of the storage
rather than peers, I hacked up the ASTWalker to optionally preserve
the old traversal order for now. This is ugly and needs to be cleaned up,
but I want to avoid breaking _too_ much with this commit.
2019-07-30 15:56:00 -04:00
Slava Pestov
a532a325e1 AST: Move a few methods from VarDecl down to ParamDecl 2019-07-22 20:19:09 -04:00
Suyash Srijan
9f3cdb92b2 [Test] Update tests 2019-06-25 01:07:14 +01:00
Suyash Srijan
701a6ca84d [Typechecker] Look through all optional types when checking for Never 2019-06-24 20:44:31 +01:00
Suyash Srijan
20cfa14423 [CSDiagnostics] Removes lazy attributes when applying computed property fix-it 2019-04-25 17:59:07 +01:00
Suyash Srijan
3ddffef3a8 [test] adds missing new line at the end of test file 2019-03-25 00:53:36 +00:00
Suyash Srijan
cad60ba08b [csdiag] offer a fix-it to turn a stored property into a computed property if needed 2019-03-22 21:21:17 +00:00
Azoy
a1bcbe8087 update tests
fix conflict with reflection test
2018-11-09 00:22:32 -06:00
Azoy
21d657ae77 add expected note 2018-11-09 00:21:14 -06:00
Azoy
18d2cc5b01 Uninhabited downgrade to warning 2018-11-09 00:21:14 -06:00
Azoy
5dcf823d8d Fix non instance member tests 2018-10-23 21:09:38 -05:00
Azoy
2973696a24 and generic enums aswell
Add generic enum test case
2018-10-23 19:33:05 -05:00
Azoy
f085c28865 Not just instance members & better diagnostic
fix some tests
2018-10-23 18:08:00 -05:00
Azoy
7991aecfce Disallow stored properties to have uninhabited types
Reword comment

Add tuple test case
2018-10-22 19:13:19 -05:00
MIZUNO Hiroki
f2bdce8251 [SR-8340]Improve fix-it for var and subscript in Protocol (#19660)
* [Parser] Improve fix-it for subscription in protocol
* [Sema] Add fix-it for property in protocol

https://bugs.swift.org/browse/SR-8340
2018-10-05 07:50:03 +09:00
John McCall
06edd256c2 Generalize the recording of parsed accessors.
As part of this, lift the now-unnecessary restriction against
combining a non-mutable addressor with a setter.  I've also
tweaked some of the diagnostics.

This is in preparation for generalized accessors.
2018-07-20 17:54:57 -04:00
David Zarzycki
71472cfa96 Enable optional unowned/unowned(unsafe) references
John okayed this change in a comment on GitHub pull request: #16237
2018-07-11 14:33:23 -04:00
John McCall
69f4dd1ec9 Generalize accessor storage to preserve the original accessor list.
Only not NFC because it's detectable by source tools.
2018-06-16 18:16:31 -04:00
David Zarzycki
f3b8b03a31 [Diag] QoI: Suggest fix-it when 'weak' has non-optional type (#16098)
Also:
1) Move and rename a type printer helper function to make this easier.
2) Improve @IBOutlet diagnostic QoI at the same time.
2018-04-23 20:55:25 -04:00
David Zarzycki
79a2e45dda [Diag] QoI: Suggest 'weak' fix-it if unowned/unmanaged is optional (#16094) 2018-04-22 15:44:48 -04:00
David Zarzycki
e326954bd0 [Diag] QoI: Add ReferenceOwnership to DiagnosticArgumentKind
By formalizing ReferenceOwnership as a diagnostic argument kind, we get
less boilerplate, better type safety, better output consistency, and
last but not least: future proofing.
2018-04-20 08:32:43 -04:00
Hamish
48f08bdbc7 [Sema] Diagnose immediate deallocation of instances assigned to non-owning variables
When performing a binding/assignment to a weak or unowned variable/property from an initialiser call, emit a warning that the instance will be immediately deallocated.
2018-03-08 16:32:35 +00:00
Doug Gregor
5c831a71ee Revert "[SE-0143] Put conditional conformances behind an "experimental" flag."
This reverts commit b59c30c1af.
2017-12-18 22:54:31 -08:00
Doug Gregor
cabdf84179 Suggest @objc for overrides of declarations from/in extensions.
The Swift class model does not support overriding declarations where either
the overridden declaration or the overriding declaration are in an extension.
However, the Objective-C class model does, so marking the declaration as
@objc (when possible) will work around the limitation.

Customize the "cannot override declaration in extension" diagnostic to
suggest adding @objc to the overridden declaration in cases where
@objc is permitted. Fixes SR-6512 / rdar://problem/35787914.
2017-12-13 14:54:32 -08:00
Doug Gregor
b59c30c1af [SE-0143] Put conditional conformances behind an "experimental" flag.
Conditional conformances aren't quite ready yet for Swift 4.1, so
introduce the flag `-enable-experimental-conditional-conformances` to
enable conditional conformaces, and an error when one declares a
conditional conformance without specifying the flag.

Add this flag when building the standard library (which will vend
conditional conformances) and to all of the tests that need it.

Fixes rdar://problem/35728337.
2017-11-28 16:01:51 -08:00
Oscar Swanros
acc3705739 [SR-5856] Test case for protocol extensions stored properties (#11934) 2017-10-12 10:32:10 -07:00
Huon Wilson
041b14175c [Sema] Remove restriction on conditional conformances. 2017-10-10 19:17:31 -07:00
Graydon Hoare
131e85fbf1 [Diagnostics] s/may/must/ in 'may not contain stored properties' 2017-09-29 16:09:23 -04:00
Graydon Hoare
0097adf4c0 [Diagnostics] s/may/must/ in 'may not also have a' 2017-09-29 16:09:23 -04:00
Matthew Baranowski
b68ece64e0 [SR-5856] Fix diagnostic for static stored properties in protocol extensions (#11930)
* [SR-5856] Fix diagnostic message for static stored properties not supported in protocol extensions

* fix test failure in decl/var/properties.swift
this looks like a better place to test the new behavior, so removing changes to static_var.swift
2017-09-17 14:07:52 -04:00
John McCall
d76263f919 Propagate accessor types directly from the storage declaration.
This eliminates the need for an ugly and incomplete hack to suppress
noescape inference for setter arguments.  It also means we stop emitting
redundant diagnostics for problems in storage types.
2017-09-10 04:56:02 -04:00
Ewa Matejska
21b2073b9e Small update to diagnostics to avoid the word yet 2017-09-07 10:34:34 -07:00
Toni Suter
b825cdce4f [Parse] [SR-5674] Add fix-it for computed 'let' declaration (#11527) 2017-08-20 13:38:50 +09:00
David Hart
6de44b0fb1 [SR-3936] Fix it for missing property type
Solve SR-3936 by providing a fix-it for the “Computed property must have an explicit type” diagnostic that insert a type placeholder.
2017-03-14 22:47:02 +01:00
Brian King
29c1fc472b Generate an error message on protocol extensions with the final attribute. 2017-03-09 14:18:39 -05:00
Jordan Rose
df63c36b72 When setting a willSet/didSet param's type, also set the TypeLoc (#7377)
We don't actually need the TypeLoc for anything, but it was still
getting type-checked, which means it doesn't get the benefit of
inference from the initial value. In some cases the actual type of the
ParamDecl seems to get reset to the TypeLoc's type as well. Just do
the simple thing and set it directly ahead of time.

Fixes a source compatibility issue with Swift 3.0.

https://bugs.swift.org/browse/SR-3893
2017-02-09 19:15:21 -08:00