Commit Graph

79 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
Allan Shortlidge
a10fcfa8c9 NFC: Subset out floating point raw value enum parsing tests.
The test/Parse/enum.swift test was only enabled for Intel platforms because a
few of the contained test cases relied on floating point literal parsing and
were not portable as a result. Subset out the non-portable test cases into a
new test so that more general enum parsing tests can run on all platforms.
2023-11-01 09:35:50 -07:00
Angela Laar
4308a1407b [Sema] Compiler should diagnose non-unique raw values without crashing
Enums with raw type `: String ` use the case name as the raw
value. So, two identical case names cause an identical raw value
error. Also, identical case names cause a separate redeclaration
error. The second error is diagnosed in a separate request in the
DeclVisitor. We may need a special case for this situation to
ignore the first error and defer diagnosing to the
CheckRedeclarationRequest. For now we will diagnose both errors.

`enum Foo : String {
    case Bar
    case Bar = "FooBar" // redclaration error only
    case Bar // redeclaration and raw value error
}`
2023-03-21 16:01:43 -07:00
Anthony Latsis
ff7f117025 Gardening: Migrate test suite to GH issues: Parse 2022-09-02 01:44:24 +03:00
Nathan Hawes
8edeab75ce [Parse] Don't drop the EnumCaseDecl when it has a trailing comma.
This meant we weren't producing sema diagnostics for the case, and it didn’t
get full syntactic/semantic highlighting or indentation.

enum CasesWithMissingElement {
  case a(Int, String),
  case b(Int, String),
}

Resolves rdar://problem/61476844
2020-04-10 18:22:33 -07:00
Pavel Yaskevich
16c1f50eda [ConstraintSystem] Diagnose incorrect use of _ during constraint generation
`_` or discard assignment expression should only be used on the left-hand
side of the assignment expression. Incorrect uses are easy to detect during
constraint generation which also allows us to avoid complications related
to other diagnostics when `_` is used incorrectly.
2020-03-24 16:51:44 -07:00
Anthony Latsis
572f0544a2 [DiagQoI] Improve fallback fixits for static member on instance error 2020-03-23 08:27:55 +03:00
Alexis Laferrière
c1618c13f1 [Parser] Fix suggested fix-its on enum case with empty parens
rdar://problem/58546221
2020-01-15 10:54:56 -08:00
Luciano Almeida
1184492d25 [Diagnostics] SR-11419 Diagnose protocol stub note in editor mode only (#28101)
* [TypeChecker] Enclosing stubs protocol note within editor mode

* [test] Removing note from test where there is no -diagnostics-editor-mode flag

* Formatting modified code

* [tests] Fixing tests under validation-tests
2019-11-06 07:42:48 -08:00
Luciano Almeida
f4423211ac SR-11261: [Diagnostics][Qol] Parser recovery for keyword (#26596)
* Fixes SR-11261
* Improving diagnostics for multi-case declaration that uses a keyword
* Only doing pattern matching if token is not a keywork or if is a possible identifier
* Using BacktrackingScope to fix expected pattern
* Updating NameLoc with the token consumed.
* Updating Name with the consumed token
2019-08-23 05:50:44 +02:00
Xi Ge
1535bea268 FixCode: issue a separate note for protocol-stub fixit when the fixit location is in another file
Under non-editor mode, the fixit for inserting protocol stubs is associated with a note
pointing to the missing protocol member declaration which could stay in a separate file from
the conforming type, leading to the behavior of rdar://51534405. This change checks if
the fixit is in a separate file and issues another note to carry the fixit if so.

rdar://51534405
2019-07-10 12:30:54 -07:00
Saleem Abdulrasool
1ab926f6ab Parse: XFAIL Parse.enum on Windows
Windows does not support FP80, only FP64.
2019-04-08 10:24:51 -07:00
Suyash Srijan
34f8670d2a [CS] Use fixes to diagnose instance member on type (or vice versa) access (#21830)
This PR migrates instance member on type and type member on instance diagnostics handling to use the new diagnostics framework (fixes) and create more reliable and accurate diagnostics in such scenarios.
2019-02-22 16:57:26 -08:00
Michael Ilseman
bca1b74427 [Character] Permit tagged emoji Character literals
Loosen up the compiler's grapheme analysis to allow the emoji tagged
sequences as graphemes.
2018-11-15 09:06:20 -08:00
Adam Shin
c7e80ebd17 [sema] Update enum error message in tests 2018-10-24 16:35:08 -06:00
Robert Widmann
e12fbc2aa2 Reject empty associated value lists
SE-0155 makes an empty associated value list in an enum element
declaration illegal.  Warn about this in legacy Swift mode, and reject
it otherwise.  This offers two fixes:
1) Remove the empty associated value list
2) Insert a 'Void' associated value
2018-08-24 10:50:23 -07:00
Matt Diephouse
35592747db Change "enum element" to "enum case" in diagnostics
From the perspective of the compiler implementation, they're elements. But users will think of these as cases—and many diagnostics already refer to these as enum cases.
2018-07-15 16:01:10 -04:00
Slava Pestov
7ca9f865f5 Sema: Move checkInheritanceClause() calls to typeCheckDecl() 2018-06-30 00:20:36 -07:00
Slava Pestov
ba30de0f08 Sema: Re-word circular inheritance diagnostics 2018-06-28 16:54:28 -07:00
Anthony Latsis
4099e85da6 [Diagnostics & Tests] SR-6052 Prevent nil capitalization (#16256)
And provide better semantic background by surrounding 'nil' in ticks when it is referred to as a value

Added missing tests for certain cases involving nil capitalization
2018-05-03 09:10:30 -07:00
Slava Pestov
025555f4b0 Sema: Remove duplicate enum case check
This is already handled by the common redeclaration check.
2018-03-22 17:47:57 -07:00
Doug Gregor
ba6f605d47 Fix some tests due to Equatable Optional/Array/Dictionary change. 2017-11-27 21:09:50 -08:00
Greg Parker
e8475cc130 Revert "Use conditional conformances to implement Equatable for Optional, Array and Dictionary" 2017-11-15 14:17:22 -08:00
Doug Gregor
9f68fdae80 [Conditional conformances] Fix up test cases that changed for the better. 2017-11-14 16:23:20 -08:00
Graydon Hoare
131e85fbf1 [Diagnostics] s/may/must/ in 'may not contain stored properties' 2017-09-29 16:09:23 -04:00
Greg Parker
b7f744c302 [test] Replace CPU=i386_or_x86_64 with CPU=i386 || CPU=x86_64. (#11889) 2017-09-12 19:34:08 -07:00
Michael Ilseman
f88fb9a97a Be a little more permissive in emoji grapheme literals.
The user experience with extended grapheme literals is currently:

1. Strict: we hard error on "invalid" grapheme literals.

2. Complete: we validate all literals to either be
known-single-grapheme or not.

3. Incorrect: we have Unicode 8 semantics implemented but applications
will have some other version of Unicode as dictated by the OS they are
running on.

In Swift 4.0, this incorrectness mostly crops up in obscure corner
case areas, where we are overly restrictive in some ways and overly
relaxed in others. But, there is one particularly embarrassing area
where it does come up: we reject emoji introduced after Unicode 8 as
grapheme literals, counter to common user expectations.

In a future (sub-)version of Swift we should completely re-evaluate
this user story, but doing so in time for Swift 4.0 is untenable. This
patch attempts to tweak the way in which we are incorrect in the most
minimally invasive way possible to preserve the same user experience
while permitting many post-Unicode-8 emoji as valid grapheme literals.

This change overrides processing of ZWJ and emoji modifiers to not
declare a grapheme break after/before, respectively.
2017-07-21 13:33:03 -07:00
Dave Abrahams
ddf7ad517f UnicodeScalar => Unicode.Scalar 2017-05-11 15:23:25 -07:00
Greg Parker
6295f3d8b3 Revert "[test] Remove CPU=i386_or_x86_64 hack."
Swift master uses LLVM swift-4.0-branch, which does not yet have
the lit change implementing this syntax.

This reverts commit dfd10ae485.
2017-02-28 14:59:31 -08:00
Greg Parker
dfd10ae485 [test] Remove CPU=i386_or_x86_64 hack.
LLVM lit now supports boolean expressions in REQUIRES: directives.
2017-02-16 16:27:15 -08:00
Slava Pestov
3f7a72eb84 Sema: Clean up diagnostic logic when deriving RawRepresentable conformance on enums 2016-12-21 14:20:26 -05:00
Robin Kunde
ab415e6b3e [Parse] Improve parser diagnostics for keyword-as-identifer errors (#6045)
Instead of the simple "expected identifier in declaration", the error will now read "keyword '%' cannot be used as an identifier here", and will be accompanied by a note suggesting escaping the keyword with backticks, as well as a fixit.

https://bugs.swift.org/browse/SR-3167
2016-12-13 16:12:53 -08: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
SpringsUp
9432a84270 [Diagnostics QOI]: More descriptive errors for synthesized RawRepresentable enums 2016-08-23 01:03:03 +02:00
SpringsUp
f9af1257ef Tighter type-checking of enums with synthesized RawRepresentable
conformance
Fixes SR-2134
2016-08-22 22:49:48 +02:00
Slava Pestov
e354ecfd45 Sema: Rip out some code for diagnosing invalid patterns
The problem here is that we would just emit 'invalid pattern'
instead of digging deeper, which meant that the fix-it for
qualified enum element access wasn't getting inserted for
more complex patterns, such as 'case X(let x)'.

Unfortunately, in the matching_patterns.swift test, we emit
too many diagnostics that are not really useful to figuring
out the problem, and the old 'invalid pattern' made more
sense. I'll work on some CSDiag tweaks to address this --
I think it makes more sense to dig there than just emit a
general 'invalid pattern' diagnostic anyway.

Fixes <rdar://problem/27684266>.
2016-08-05 14:27:17 -07:00
Slava Pestov
22aa032285 Sema: Clean up SE-0036 diagnostic a bit
Suggest a fix-it for unqualified references to all static members
from instance context, not just enum elements.

Also, fix a small problem with the fix-it for replacing protocol
names with 'Self' inside extension bodies -- we didn't handle nested
functions properly.
2016-08-05 14:27:16 -07:00
practicalswift
7e89679404 [gardening] Fix recently introduced typos. 2016-07-24 22:32:40 +02:00
Alex Hoppen
095a68b195 [Sema] Disallow accessing enum elements as instance members
This implements SE-0036.
2016-07-20 19:13:58 +02:00
Alex Hoppen
232fe59b54 [Sema] Don't issue warnings when accessing enum elements as instance members
This removes the logic which issued warnings when accessing enum
elements as instance members (SE-0036), making room for a new
implementation that will issue errors instead.

This reverts commit ae1058a39a.
2016-07-20 16:25:57 +02:00
Robert Widmann
f97e5dcb0e [SE-0115][1/2] Rename *LiteralConvertible protocols to ExpressibleBy*Literal. This
change includes both the necessary protocol updates and the deprecation
warnings
suitable for migration.  A future patch will remove the renamings and
make this
a hard error.
2016-07-12 15:25:24 -07:00
Alex Hoppen
ae1058a39a [Sema] Provide warnings when accessing enum elements as instance members as a preparation for SE-0036 2016-07-08 11:17:46 +02:00
Ted Kremenek
942e524285 Revert "SE-0036: Requiring Leading Dot Prefixes for Enum Instance Member Implementations" (#2477) 2016-05-11 11:02:37 -07:00
Alex Hoppen
0e8c69c56f [SE-0036]: Requiring Leading Dot Prefixes for Enum Instance Member Implementations 2016-05-07 22:39:26 +02:00
Max Moiseev
0b759a409c Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-23 14:26:14 -08:00
Daniel Duan
e0cc095063 [Parser] updated tests for "expected declaration" companion note 2016-02-19 11:05:03 -08:00
Dmitri Gribenko
65d840c0ae stdlib: lowercase cases in Optional and ImplicitlyUnwrappedOptional 2016-02-18 00:40:33 -08:00
David Farler
3f635d04c7 Reinstante var bindings in refutable patterns, except function parameters.
This reverts commits: b96e06da44,
                      8f2fbdc93a,
                      93b6962478,
                      64024118f4,
                      a759ca9141,
                      3434f9642b,
                      9f33429891,
                      47c043e8a6.

This commit leaves 'var' on function parameters as a warning to be
merged into Swift 2.2. For Swift 3, this will be an error, to be
converted in a follow-up.
2016-01-29 15:27:08 -08:00
gregomni
b4b77fbedb [AST] Fix argument to diagnostic
A simple “%1” to “%0” for a diagnosis with just one arg, along with a test case for it.
2016-01-19 15:31:47 -08:00
David Farler
a759ca9141 Disallow 'var' bindings in case patterns
Make the following illegal:

switch thing {
  case .A(var x):
    modify(x0
}

And provide a replacement 'var' -> 'let' fix-it.

rdar://problem/23172698

Swift SVN r32883
2015-10-25 18:53:02 +00:00