Commit Graph

62 Commits

Author SHA1 Message Date
Minhyuk Kim
c0eab4f551 Change error message to specify when inout usage is allowed 2023-09-24 23:18:27 +09:00
Anthony Latsis
da566542b4 Gardening: Migrate test suite to GH issues: decl/enum 2022-08-26 03:26:32 +03:00
Pavel Yaskevich
7009207491 [ConstraintSystem] Adjust handling of incorrect member references on protocol metatypes
Since it's now possible to refer to static members declared on a protocol
metatype if result type conforms to the protocol we need to adjust failure
detection to identify that conformance failure means and invalid reference
in certain situations.
2021-02-23 11:32:24 -08:00
Minhyuk Kim
7eaabe1996 Simplify unused lvalue warning wording 2021-01-15 22:14:56 +09:00
Luciano Almeida
d954b840fd [tests] Adjusting SR-11535 test case on the suit 2020-12-05 22:48:09 -03:00
Luciano Almeida
cba7029329 [NFC] Correcting test case for SR-11535 and adding a explanation comment 2020-12-05 22:48:09 -03:00
Pavel Yaskevich
79a2ab0c8c [ConstraintSystem] Record unable to infer base only if hole originated from affected reference
If base type of a unresolved member reference couldn't be determined
(represented as a hole type), before recording a fix about lack of
contextual information, let's make sure that hole originated in either
base or result type of this reference, otherwise the problem is
contextual e.g. generic parameter, which supposed to act as contextual
type for a reference, couldn't be inferred.
2020-09-07 11:44:51 -07:00
Pavel Yaskevich
5f328ad003 [ConstraintSystem] Don't increase SK_Fix score when looking through holes
`SK_Fix` was used to indicate that solver has encountered a hole
along the current path but since there is `SK_Hole` now, increasing
`SK_Fix` no longer makes sense.
2020-03-25 09:34:00 -07:00
Varun Gandhi
d58bf546be [Diagnostics] Improve diagnostics for implicit (un)tupling. (#28076)
Fixes rdar://problem/56436226.
2020-02-13 17:38:21 -08:00
Suyash Srijan
74cfee1485 [Typechecker] Extended ambiguous none warning to cases as well (#29356) 2020-01-23 22:04:08 +00:00
Pavel Yaskevich
5cacd1bb36 [ConstraintSystem] Fix situations when contextual base type can't be inferred
It might be either impossible to infer the base because there is
no contextual information e.g. `_ = .foo` or there is something
else wrong in the expression which disconnects member reference
from its context.
2019-12-03 12:07:16 -08:00
Pavel Yaskevich
2dd87c7758 [Diagnostics] NFC: Adjust a couple of test-cases improved after generic parameter fix 2019-11-05 16:52:30 -08:00
Holly Borla
561e527848 [ConstraintSystem] Extend the ExplicitlySpecifyGenericArguments fix to cover
all cases of missing generic parameters.

In `ComponentStep::take` when there are no bindings or disjunctions, use hole
propagation to default remaining free type variables that aren't for generic
parameters and continue solving. Rather than using a defaultable constraint for
holes, assign a fixed type directly when we have no bindings to try.
2019-11-05 09:15:13 -08:00
Suyash Srijan
b3d7962598 [Test] Add some more tests around edge cases 2019-09-28 00:09:52 +01:00
Suyash Srijan
389232ac86 [Test] Add a FIXME next to a test case that should be diagnosed 2019-09-27 02:23:42 +01:00
Suyash Srijan
aa565f550c [CSApply] Compare variable's type with the base type of the enum we're assigning to 2019-09-26 20:49:25 +01:00
Suyash Srijan
25e1bb5ac1 [CSApply] Filter out functions and instance members before the ambiguous none check 2019-09-26 20:10:50 +01:00
Suyash Srijan
8d869e6f23 [CSApply] Don't diagnose a 'static let none' as ambiguous none unless its type matches the enum 2019-09-26 19:02:37 +01:00
Varun Gandhi
e365b6be7d Implicitly untuple patterns if applicable and add warnings. 2019-08-12 09:58:22 -07:00
Slava Pestov
7566f98a45 Sema: Diagnose enum inheritance clause containing subclass existential
Also, tidy up the code a bit and stop emitting redundant diagnostics for
associated types.

Fixes <https://bugs.swift.org/browse/SR-10232>.
2019-04-01 22:41:16 -04:00
Suyash Srijan
f30ba3069b [Sema] Add warning for ambiguous value assignment when using Optional (#21621)
* [sema] emit a diag if the enum case matches Optional<T>.none

* [test] update tests

* [sema] fix indent

* [test] fix indent

* [test] add more test cases

* [test] add even more test cases

* [sema] move the check to CSApply

* [diag] update diagnostic message

* [test] update tests

* [test] fix conflicts

* [diag] reflow lines

* [sema] reindent using spaces

* [test] adds new line

* [diag] update diagnostic message

* [sema] add support for structs as well

* [test] add more test cases

* [sema] check for enum assoc values

* [test] add more test cases

* [diag] add fixit notes

* [sema] emit fix its

* [diag] rename diag names

* [sema] fit within 80 char line limit

* [sema] use baseUnwrappedType's name directly

* [test] adds nested generic enum tests

* [test] fix indent

* [test] adds fixit check

* [test] re-indent some enums

* [sema] [csapply] extract code into a separate function

* [sema] [csapply] remove redundant vardecl check

* [sema] [csapply] reindent

* [sema] [csapply] removes extra line

* [sema] [csapply] use cantype & check for extension on Optional

* [diag] update diagnostic message

* [sema] [csapply] fix ident

* [test] update tests

* [sema] [csapply] fix typo and remove redundant isOptional check

* [sema] [csapply] update var name & comments

* [sema] [csapply] bring back isOptional check

* [test] add expected-note for fix-its

* [sema] [csapply] fix a crash

* [sema] [csapply] move isOptional check outside

* [test] fix indent

* [test] fix typo

* [sema] [csapply] use baseTyUnwrapped for fixit

* [test] fix columns for fixits

* [test] update column numbers

* [sema] [csapply] move code out of for loop
2019-01-07 20:56:14 -05:00
John McCall
6e5ce64db1 Ban variadic enum cases.
These should be supported in the long term, but in the short term,
crashing is not accepable behavior.

rdar://46821582
2018-12-18 17:27:48 -05:00
Slava Pestov
8cfe7377e3 Sema: Ban single-element tuple expressions
Fixes <rdar://problem/30384023>, <rdar://problem/41474370>,
and <https://bugs.swift.org/browse/SR-8109>.
2018-12-15 00:07:04 -05:00
Matt Diephouse
b4a2dc8add Improve contextual member unexpected arguments diagnostic 2018-07-23 20:18:40 -04:00
Slava Pestov
366d9a8182 Sema: Clear more type resolution flags for single-argument function types
This fixes a 4.2 regression where enums and subscripts could not
contain single-argument function types with an 'inout' parameter,
because we erroneously diagnosed the 'inout' as if it appeared
at the top level of the enum case or subscript index type.

Fixes <https://bugs.swift.org/browse/SR-7890>.
2018-06-06 22:55:01 -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
435d66f70b Sema: Add separate pass for checkConformancesInContext()
I tried doing this directly from typeCheckDecl(), but it breaks
associated type inference. We can figure this out later when
declaration checking becomes lazier and more incremental.

Note that typo correction does not force witnesses of
synthesized conformances. This means that a typo correction
from a top-level form will no longer pick up synthesized
witnesses, and will find the protocol requirement instead.

To give a test the same behavior as before, I put the
expression in a function body instead of a top-level form.

Note that we already had the same behavior with typo
correction from pattern binding initializers and other
contexts that are type checked before conformances.
2018-04-06 00:55:43 -07:00
Mike JS. Choi
3745d6b896 [Diagnostics] Provide contextual type when diagnosing invalid if-exp
Resolves [SR-910](https://bugs.swift.org/browse/SR-910).
2017-08-27 17:18:47 -05:00
Max Moiseev
90ef26824f Merge remote-tracking branch 'origin/master' into new-integer-protocols 2017-01-26 15:28:42 -08:00
Slava Pestov
4148079a9e Sema: Change diagnostics to not talk about 'materializable' types
This is not a term we want users to have to care about.
2017-01-23 23:54:50 -08:00
Max Moiseev
e1de9fcf0c More test fixes 2017-01-09 16:17:21 -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
Jacob Bandes-Storch
bc3a7d1241 [QoI] improve diagnostics for contextual members with argument mismatch 2016-08-28 15:59:41 -07:00
John McCall
6593c5319d Add typo correction to qualified lookup. 2016-07-01 19:04:57 -07:00
Chris Lattner
3549ec5404 [QoI] make several improvements to the unused expression diagnostics, to go
along with recent policy changes:

- For expression types that are not specifically handled, make sure to
  produce a general "unused value" warning, catching a bunch of unused
  values in the testsuite.

- For unused operator results, diagnose them as uses of the operator
  instead of "calls".

- For calls, mutter the type of the result for greater specificity.

- For initializers, mutter the type of the initialized value.

- Look through OpenExistentialExpr's so we can handle protocol member
  references propertly.

- Look through several other expressions so we handle @discardableResult
  better.
2016-05-16 23:26:07 -07:00
Trent Nadeau
0cc851568a Updated tests to use @discardableResult and _ = . 2016-05-11 22:53:38 -04: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
practicalswift
abfecfde17 [gardening] if ([space]…[space]) → if (…), for(…) → for (…), while(…) → while (…), [[space]x, y[space]] → [x, y] 2016-04-04 16:22:11 +02:00
Dmitri Gribenko
65d840c0ae stdlib: lowercase cases in Optional and ImplicitlyUnwrappedOptional 2016-02-18 00:40:33 -08:00
Dmitri Gribenko
efaa39ea79 stdlib: add first argument labels and some other changes to conform to API guidelines 2016-02-15 23:47:54 -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 Lattner
995506a5e2 Improve the generic "expression...is ambiguous without more context" error in a few ways:
- Improve the specific cases of nil and empty collection literals.
- Improve cases of contextual member lookup where the result type of the looked up member disagrees with context.
- Add some fixme's to the testsuite for cases of this diagnostic that should be diagnosed in other ways.
2016-01-22 22:58:26 -08:00
Doug Gregor
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Chris Lattner
849ec50a12 Fix <rdar://problem/21269142> Diagnostic should say why enum has no .rawValue member
If someone is trying to refer to the rawValue of an enum that has no
raw type, give them a hint that they need to go do that.
2016-01-17 15:35:22 -08:00
Daniel Duan
ce8be70cdb fix raw value error test introduced in #955 2016-01-14 22:00:54 -08:00
Chris Lattner
bce19d4d00 Merge pull request #955 from dduan/SR-510-2
[SR-510][Parser] complain for invalid enum raw value
2016-01-14 21:56:22 -08:00
Daniel Duan
3f96a204de add test for invalid enum raw value diagnosis 2016-01-13 01:28:02 -08:00
Chris Lattner
3085094441 fix <rdar://problem/23942743> [QoI] Bad diagnostic when errors inside enum constructor
On something like this:
  let x = .Tomato(cloud: .None)

we previously emitted a "type of expression is ambiguous without more context" error
while pointing to .None.  With a previous fix, we now produce the same error pointing
to the .Tomato.  With this fix, we now produce:

error: reference to member 'Tomato' cannot be resolved without a contextual type

to really drive the problem home.
2016-01-11 19:37:12 -08:00
Max Moiseev
2f7b64e475 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-21 12:02:13 -08:00
Daniel Duan
239c6629e9 Remove trailing semi-colons in .swift files 2015-12-20 21:12:11 -08:00