Commit Graph

975 Commits

Author SHA1 Message Date
Slava Pestov
ae6c75ab5d Sema: Fix availability of inherited designated initializers
Inherited designated initializers got the same availability
as the corresponding initialier in the superclass.

However if the superclass was more available than the subclass,
we would generate a diagnostic that a member cannot be more
available than its containing type.

This diagnostic had an unknown source location, since the
location was for a synthesized declaration, causing confusion.

Fixes <https://bugs.swift.org/browse/SR-7881> aka
<rdar://problem/40853731>.
2018-06-08 23:23:43 -07:00
fischertony
abb864dd3e naming changes 2018-06-06 08:11:15 +03:00
fischertony
b576a40428 message amendments 2018-06-05 03:22:11 +03:00
fischertony
b568a22e5a change naming & concretize diag message 2018-06-05 02:42:57 +03:00
fischertony
6cf25b1eea [Diagnostics][Sema] warn inconstructible enum 2018-06-04 20:08:31 +03:00
Ding Ye
95b95e3d99 [Sema] Fix spurious use_local_before_declaration errors.
When performing name lookup for UnresolvedDeclRefExpr, if a
local declaration after use is detected, we check outer results
to see if we can find better matching candidates before raising
a use_local_before_declaration error.

Resolves: SR-7660.
2018-06-03 19:59:45 +10:00
swift-ci
81ce77d510 Merge pull request #16644 from ravikandhadai/LargeIntOverflowPR 2018-05-21 20:37:47 -07:00
Ravi Kandhadai
f1ff8a61a5 [Sema] Add Sema checks for detecting large integer literals that
overflow Builtin.Int2048 and add tests for checking the
correctness of the diagnostics.
2018-05-21 18:41:44 -07:00
Slava Pestov
7ed2f8cc21 SIL Printer: Fix crash when @_specialize attribute applied to a declaration
We have no generic environment in this case, and just need to print
the canonical generic parameter types.

Fixes <https://bugs.swift.org/browse/SR-7673>.
2018-05-13 22:51:17 -07:00
Michael Ilseman
600326194d [test] XFAIL crashing Sema test 2018-05-13 08:29:22 -07:00
Slava Pestov
66ccbcb839 Sema: Fix access control regression with generic type aliases
If a property had an inferred type that is a generic type alias,
we weren't checking the access level of the generic arguments.

This used to work in 4.1 because we didn't have a sugared
representation for generic type aliases, so we were checking
the substituted underlying type here. But now that NameAliasType
can store generic arguments, make sure we visit them here.

Fixes <rdar://problem/40188409>.
2018-05-12 01:41:54 -07:00
Slava Pestov
47239ec88c Sema: Fix bug with private access scopes in Swift 3 mode
In Swift 3 mode, the canonical private DeclContext should
not look through extensions.

The only way I can reproduce this is with a missing warning
and we don't really care about missing warnings in Swift 3 mode.

However, the next patch in this PR regresses more things so
let's fix it properly.
2018-05-12 01:40:11 -07:00
Jordan Rose
6bd7e5e5b4 Make sure protocol witness errors don't leave the conformance context
That is, if there's a problem with a witness, and the witness comes
from a different extension from the conformance (or the original type,
when the conformance is on an extension), put the main diagnostic on
the conformance, with a note on the witness. This involves some
shuffling and rephrasing of existing diagnostics too.

There's a few reasons for this change:

- More context. It may not be obvious why a declaration in file
  A.swift needs to be marked 'public' if you can't see the conformance
  in B.swift.

- Better locations for imported declarations. If you're checking a
  conformance in a source file but the witness came from an imported
  module, it's better to put the diagnostic on the part you have
  control over. (This is especially true in Xcode, which can't display
  diagnostics on imported declarations in the source editor.)

- Plays better with batch mode. Without this change, you can have
  diagnostics being reported in file A.swift that are tied to a
  conformance declared in file B.swift. Of course the contents of
  A.swift also affect the diagnostic, but compiling A.swift on its
  own wouldn't produce the diagnostic, and so putting it there is
  problematic.

The change does in some cases make for a worse user experience,
though; if you just want to apply the changes and move on, the main
diagnostic isn't in the "right place". It's the note that has the info
and possible fix-it. It's also a slightly more complicated
implementation.
2018-05-10 19:31:12 -07:00
Jordan Rose
545b12fa9f Convert backticks to single-quotes in Sema diagnostics
Let's be consistent!
2018-05-09 21:59:39 -07:00
Huon Wilson
fe7240ab8a [Sema] Disallow synthesis-in-extensions in Swift 3.
'private' properties can't be accessed in extensions in Swift 3, so synthesizing
a conformance that reads from such things is going to be incorrect in an
extension.
2018-05-09 09:55:41 +10:00
Jordan Rose
0b0671ce33 Merge pull request #16430 from nuclearace/better-lazy-diag
[Diagnostics] Better lazy ownership error
2018-05-08 13:33:35 -07:00
Erik Little
f3df14cbee Simplify lazy ownership tests/checking 2018-05-08 12:07:59 -04:00
Erik Little
89ad43e87b Fix test for lazy ownership; Better diag 2018-05-08 09:30:13 -04:00
David Zarzycki
44a6d99158 Merge pull request #16422 from davezarzycki/objc_interop_check
[Sema] Error if ObjC interop is needed when disabled
2018-05-08 05:51:15 -04:00
Mark Lacey
501a641c78 Merge pull request #16434 from rudkx/rdar39886178
Conditionalize warnings for IUO-to-Any coercion on Swift version.
2018-05-07 22:21:03 -07:00
Mark Lacey
08f80ec361 Properly handle subscripts when avoiding IUO-to-Any coercion warnings.
Ensure that we grab the decl from the subscript expression so that we
can check whether it returns an IUO.

Also add tests for subscripts and failable inits.
2018-05-07 18:10:57 -07:00
Mark Lacey
dbb5bc44db Add a couple additional tests for Optional-to-Any warnings. 2018-05-07 16:11:47 -07:00
Mark Lacey
a61a6d536e Conditionalize warnings for IUO-to-Any coercion on Swift version.
These warnings are turning out to be pretty noisy for code that
declares IUOs (e.g. for @IBOutlets) and then passes them to
Objective-C APIs with parameters declared as _Nonnull id.

Since we bridge non-nil values successfully in most cases, and
previuosly written and correctly executing code is either not seeing
nil values passed in or are handling the nil (which is bridged as
NSNull), it seems like a nuisance to warn about these for existing
Swift versions.

We'll conditionalize the warning, and then users can deal with these
when moving to the new language version.

Fixes: rdar://problem/39886178
2018-05-07 15:49:56 -07:00
Erik Little
73a03d667f [Diagnostics] Better lazy ownership error
Intead of just spitting out some non-sensical error,
properly tell the user that lazy properties shouldn't
have ownership attributes.
2018-05-07 15:56:20 -04:00
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
Huon Wilson
041287f0ba [Sema] Fix synthesis of CaseIterable conformances in extensions of generic types.
https://bugs.swift.org/browse/SR-6803
2018-05-07 09:41:26 +10:00
Huon Wilson
47e643af0e [Sema] Fix synthesis of Equatable and Hashable conformances in extensions of generic types.
https://bugs.swift.org/browse/SR-6803
2018-05-07 09:41:25 +10:00
Huon Wilson
3488a3a53b [Sema] Allow synthesis of protocol conformances in extensions.
This works for all protocols except for Decodable on non-final classes, because
the init requirement has to be 'required' and thus in the type's declaration.

Fixes most of https://bugs.swift.org/browse/SR-6803.
2018-05-07 09:41:25 +10:00
David Ungar
ea749c2b36 Scan output twice to strengthen negative checks. 2018-05-04 19:03:36 -07:00
David Ungar
757dcf0cb0 Provisional test for exhaustiveness cutoff. 2018-05-04 13:44:03 -07:00
David Ungar
41b2281c03 Update tests to new message 2018-05-02 15:49:29 -07:00
David Ungar
9c74f8108d Fix tests for new diagnostic. 2018-05-02 15:49:29 -07:00
Pavel Yaskevich
3ea663571d [Sema] SpaceEngine: Improve handling of empty/non-reduced spaces in construtors/disjuncts
Eagerly remove empty (sub-)spaces from constructors and disjuncts
to minimize number of operations required to check space coverage.
Also return original constructor space while subtracting a pair of
constructors, instead of disjunct, if subtraction of one of its
sub-spaces produced the same space, this reduces the number of
disjuncts in the path.

Resolves: rdar://problem/39710335
2018-05-01 23:46:36 -07:00
Anthony Latsis
79c0516133 [Diagnostics] SR-7349 Improve accessibility diagnostics for inheritance from generic classes (#16223)
* [Diagnostics] Improve accessibility diagnostics for inheritance from generic classes

Fixed misleading warning when message pointed to the type's superclass access level instead of the access level of the type used as a generic parameter of the superclass when inheriting

* updated 'Compatibility' tests (warnings)

* updated the diagnostic's error version

Resolves: SR-7349
2018-04-28 15:54:33 -07:00
Anthony Latsis
96c0c13a2b [Diagnostics] SR-7445 Improve diagnostics for assignment failures (#16179)
* [Diagnostics] SR-7445 Improve diagnostics for assignment failures

* modified messages for assignments to function calls,
   modified messages for assignments to methods.
   removed comment for resolved radar.

* removed extra line and braces

* added tests for assignment_lhs_is_apply_expression
   eliminated redundant literal check which is always invoked before call
   reverted 'cannot assign to value' for literal assignments in subexpressions

* Complemented assigning to literal tests & reverted to 'cannot asign to value' for methods (was 'cannot assign to member')

* removed extra tabs

* eliminated one more accidental spacing

* Update CSDiag.cpp

* added highlighting, fixed & rechecked tests

* added highlighting for complex expressions involving assigning to literals

Resolves: [SR-7445](https://bugs.swift.org/browse/SR-7445)
2018-04-28 15:49:10 -07:00
Robert Widmann
644846ffee [SR-7554] Re-project cast subpatterns
A corner-case left over from an earlier fix that made exhaustiveness
checker aware of irrefutable coercions.  If the coercion occured as part
of a sub-pattern, that pattern would be projected with the wrong type
and would fail the intersection test.  Project the pattern with the type
of the scrutinee instead.
2018-04-26 20:54:59 -04:00
Robert Widmann
7edc266c3d [SR-7492] Project over-parenthesized patterns properly
Projection assumed if it ever hit a case where an argument pattern
contained extra parentheses that the user was trying to create
a var pattern to bind the entire argument tuple.

enum Foo {
  case bar(Int, String, Float)
}

switch fooVal {
  case bar(let x): ...
}

This breaks in the presence of tuple patterns with extra parentheses.
Treat these patterns explicitly when projecting them.
2018-04-26 16:28:46 -04:00
Slava Pestov
7cb6cd65f8 Sema: Add a test case for a typo correction crash that's already been fixed
I think this is one of the cases from <rdar://problem/36434823>;
it was fixed by commit 09cc86011f.
2018-04-25 17:32:29 -07:00
Karoy Lorentey
110ee052b1 [SE-0206][test] Update diagnostic tests for Hashable derivation 2018-04-24 17:43:23 +01:00
Saleem Abdulrasool
64268be652 test: invoke python tools properly
Ensure that we use the correct python to run the python based tools.
This also allows these tools to run on Windows which will not
necessarily associate the python script with an interpreter (python).
2018-04-23 17:30:09 -07:00
Jordan Rose
797901fc41 Enable @unknown default warnings by default in Swift 5 mode (#16045)
Note that I said "warnings"; we're going to be more cautious about
rollout and just make this a warning in Swift 5 mode, with /no/
diagnostics in Swift 3 and 4. Users are still free to use `@unknown
default` in these modes, and they'll get a fatal run-time error if
they don't and an unexpected case actually shows up.

rdar://problem/29324688
2018-04-20 17:04:31 -07: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
Jordan Rose
28a1dc7770 Use 'fileprivate' for synthesized members of 'private' decls (#15980)
Since 'private' means "limit to the enclosing scope (and extensions
thereof)", putting it on a member means that the member can't be
accessed everywhere the type might show up. That's normally a good
thing, but it's not the desired effect for synthesized members used
for derived conformances, and when it comes to class initializers this
actually violates AST invariants.

rdar://problem/39478298
2018-04-17 15:19:35 -07:00
Jordan Rose
a9f26ab893 Don't crash when using @unknown default with a non-enum type.
Also improve the error message when using it with a very large space.

https://bugs.swift.org/browse/SR-7408
2018-04-11 19:28:39 -07:00
Jordan Rose
7405d515be Don't include unavailable cases in switch exhaustivity checking (#15849)
At one point compiler wouldn't let you use them in matches, so people have
had to use catch-all cases instead. SILGen already handles this because of
@_downgrade_exhaustivity_check, as well as non-exhaustive enums in
Swift 4 mode.

rdar://problem/33246586
2018-04-10 14:00:14 -07:00
Jordan Rose
6d30272bfd Merge pull request #14382 from jrose-apple/unknown-case
Implementation for `@unknown default`
2018-04-10 11:19:53 -07:00
John McCall
7815892a76 Add unique typo corrections to the main diagnostic with a fix-it.
Continue to emit notes for the candidates, but use different text.
Note that we can emit a typo correction fix-it even if there are
multiple candidates with the same name.

Also, disable typo correction in the migrator, since the operation
is quite expensive, the notes are never presented to the user, and
the fix-its can interfere with the migrator's own edits.

Our general guidance is that fix-its should be added on the main
diagnostic only when the fix-it is highly likely to be correct.
The exact threshold is debateable.  Typo correction is certainly
capable of making mistakes, but most of its edits are right, and
when it's wrong it's usually obviously wrong.  On balance, I think
this is the right thing to do.  For what it's worth, it's also
what we do in Clang.
2018-04-07 16:01:39 -04:00
Slava Pestov
a5579d1cff AST: Plug a hole in access control checking
A protocol extension of a private protocol can define internal
or public members. We should not be able to find these members
from another file or module if an internal or public type
conforms to the protocol.

Fixes <rdar://problem/21380336>.
2018-04-05 23:24:48 -07:00
Jordan Rose
7c689c322e Prefer @unknown default over @unknown case _ in diagnostics
(and fix-its)
2018-04-05 17:54:49 -07:00
Jordan Rose
ceb51eea80 Clean up fix-it generation for missing cases, esp. with '@unknown'
- Combine the common logic for editor mode and non-editor mode.
- Do a better job minimizing fix-its.
- If '@unknown' is the only missing case, put `fatalError()` in the
  Xcode placeholder, since that's what the compiler would have done.
2018-04-05 16:35:15 -07:00