Commit Graph

46 Commits

Author SHA1 Message Date
Henrik G. Olsson
cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -07:00
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
Anthony Latsis
cafcb868df Gardening: Migrate test suite to GH issues: Sema (2/2) 2022-09-02 11:04:36 +03:00
Pavel Yaskevich
61a850dfc3 [CSFix] Improve missing .rawValue fix in ambiguity conditions 2022-08-03 15:50:33 -07:00
Slava Pestov
8464afd738 Sema: Remove SourceFile::SynthesizedDecls 2021-04-21 00:07:29 -04:00
Pavel Yaskevich
2e2792e3e3 [ConstraintSystem] Adjust diagnoseAmbiguity to use a local slice of overloads
Compute a slice of ambiguous overload choices related to an aggregated fix
and if such a slice points to a single overload diagnose it as non-ambiguous.
2020-11-06 10:42:25 -08:00
Slava Pestov
dfbb958ced Sema: Try to derive type witnesses before running inference
Sema can infer type witnesses for a small set of known conformances, to
RawRepresentable, CaseIterable, and Differentiable.

Previously, we would try to compute the type witness in this order:

1) First, via name lookup, to find an explicit nested type with the
   same name as an associated type.

2) Second, we would attempt inference.

3) Third, we would attempt derivation.

Instead, let's do 3) before 2). This avoids circularity errors in
situations where the witness can be derived, but inference fails.

This breaks source compatibility with enum declarations where the raw
type in the inheritance clause is a lie, and the user defines their
own witnesses with mismatched types. However, I suspect this does not
come up in practice, because if you don't synthesize witnesses, there
is no way to access the actual raw literal values of the enum cases.
2020-06-26 19:46:52 -04:00
Pavel Yaskevich
82fcee7bc7 [Diagnostics] NFC: Adjust diagnostic test-cases improved by new ambiguity diagnosis 2020-06-12 13:13:27 -07:00
Pavel Yaskevich
0f6665cae6 [Diagnostics] Adjust fix-it when .rawValue is missing from optional type 2020-06-02 12:50:13 -07:00
Pavel Yaskevich
9805b0ab89 [ConstraintSystem] Do more checking before suggesting to use of .rawValue
Introduce `repairByUsingRawValueOfRawRepresentableType` which is used for
assignment, argument-to-parameter conversions and contextual mismatches.

It checks whether `from` side is a raw representable type and tries
to match `to` side to its `rawValue`.

Also extract logic common for `repairByUsingRawValueOfRawRepresentableType`
and `repairByExplicitRawRepresentativeUse` into `isValueOfRawRepresentable`.
2020-06-01 14:10:24 -07:00
Pavel Yaskevich
f048652a2b [ConstraintSystem] Do more checking before suggesting to explicitly contruct raw representable
Introduce `repairByExplicitRawRepresentativeUse` which is used for
assignment, argument-to-parameter conversions and contextual mismatches.

It checks whether `to` side is a raw representable type and tries
to match `from` side to its `rawValue`.
2020-05-29 12:14:07 -07:00
Robert Widmann
2966a38ee1 Do a little extra validation of RawRepresentable.RawValue
* In the DeclChecker, duplicate the check that we have a reasonable
RawValue type so we do not attempt to form an invalid key. The interface
to the autoincrementer has this as invariant, but it was not previously
checked as a precondition.

* In the deriver, try to check for the case where the user has written
a mismatched explicit declaration of RawValue, or a type sharing that
name, and check type equality with the declared raw type to make this
pass resilient to mismatches as well.

Resolves rdar://57072148, rdar://59703784
2020-03-16 09:59:09 -07:00
Slava Pestov
1dd527ef4e Sema: Fix crash when synthesizing RawRepresentable conformance with non-Equatable raw type
The error recovery logic around derived conformances is a little bit
tricky. Make sure we don't crash if a type explicitly provides a
RawValue type witness that is not equatable, but omits the witnesses
for init(rawValue:) and the rawValue property.

Fixes <rdar://problem/58127114>.
2020-01-13 19:07:06 -05: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
Robert Widmann
233f8645d1 Move some more common enum diagnostics into the decl checker
In preparation for checkEnumRawValues being turned into a request, move the common diagnostics to the decl checker so they're always emitted at the right time.
2019-09-26 11:07:03 -07: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
Adam Shin
c7e80ebd17 [sema] Update enum error message in tests 2018-10-24 16:35:08 -06:00
Jordan Rose
c468ca1e48 Handle stray LoadExprs in RawRepresentable fix-its (#17804)
When there are multiple possible overloads for a call, the partially-
type-checked argument expression might end up with a LoadExpr outside
of the call ParenExpr instead of inside it. Account for this in a one-
off way for the 'rawValue' / 'init(rawValue:)' fix-its.

Yet more https://bugs.swift.org/browse/SR-8150
2018-07-09 15:22:18 -07:00
Jordan Rose
b318ab125d Prefer RawRepresentable fix-its that don't require an extra conversion
That is, if a type has a raw value of Int, and the function being
called has overloads for both Int and UInt, we always want to offer a
fix-it that leads to the 'Int' overload, not insert a conversion to
UInt that might be incorrect.

More https://bugs.swift.org/browse/SR-8150.
2018-07-03 13:24:36 -07:00
Jordan Rose
cc82ae00d9 Fix RawRepresentable fix-its for single unlabeled arguments
They were being put outside the call parentheses instead of inside.
We even had tests for this; I just got them wrong.

https://bugs.swift.org/browse/SR-8150
2018-07-03 13:24:22 -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
8a3191177d Sema: DeclChecker::visitPatternBindingDecl() does everything in the 'first pass' 2018-04-03 14:39:30 -07:00
Slava Pestov
b87944d52c Sema: DeclChecker::visitEnumDecl() does everything in the 'first pass' 2018-04-02 23:17:59 -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
gregomni
345c4a933d Save unresolved arg number from callee candidate info, use it to diagnose ambiguity sooner and
more specifically.
2017-10-22 10:32:11 -07:00
Pavel Yaskevich
2bec75e069 [QoI] Fix position of the fix-it related to raw representable conversion
Part of the fix-it for conversion from optional to raw representable
was inserted at the incorrect position which produces invalid expression.

Resolves: rdar://problem/32431736
2017-07-18 22:13:20 -07:00
Pavel Yaskevich
2d8dca0266 [QoI] Improve diagnostic for raw representable argument mismatch
Covers some common situations when switching from literal types e.g.
string or int to more Swift Way of raw representable enum of choices.

Resolves: rdar://problem/32431165, rdar://problem/31977537, rdar://problem/32432253
2017-06-02 18:22:23 -07:00
Pavel Yaskevich
c94fe94d5d [Diagnostics] Add a fix-it for optional to raw representable type conversion
Situations where there is a contextual RawRepresentable type is
used incorrectly would produce `<Type>(rawValue: )` fix-it only
in cases where neither or both sides of the expression are optional.
Let's fix that by adding a fix-it for optional to contextual raw
value type conversion.

Resolves: rdar://problem/32431736
2017-05-31 13:58:17 -07:00
Slava Pestov
3f7a72eb84 Sema: Clean up diagnostic logic when deriving RawRepresentable conformance on enums 2016-12-21 14:20:26 -05: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
nohirap
52e426c07f Modify forget. 2016-07-10 16:00:17 +09: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
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Joe Groff
8338e69c86 Actually set up the 'rawValue' argument label on derived enum initializers.
Somehow, protocol conformance checking didn't actually care that this was missing...

Swift SVN r21898
2014-09-12 01:29:51 +00:00
Joe Groff
491e47cb83 Rename RawRepresentable.raw -> rawValue.
Per API review with Ali. While we're here, give the initializer a corresponding 'rawValue' argument label, and change the associated type name to RawValue to match.

Swift SVN r21888
2014-09-11 20:13:47 +00:00
Joe Groff
419ba5cbea Change RawRepresentable to use failable initializers and property requirements.
Redefine the RawRepresentable protocol to use an 'init?' method instead of 'fromRaw(Raw)', and a 'raw' get-only property instead of 'toRaw()'. Update the compiler to support deriving conformances for enums and option sets with the new protocol. rdar://problem/18216832

Swift SVN r21762
2014-09-06 18:40:14 +00:00
Dave Abrahams
6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00
Doug Gregor
f0159f40a1 Ban the "new" syntax for creating an array <rdar://problem/16951969>.
We haven't been advertising this syntax much, and it's closure form
was completely broken anyway, so don't jump through hoops to provide
great Fix-Its here. 


Swift SVN r19277
2014-06-26 23:51:47 +00:00
Doug Gregor
9210cd5ff4 Replace T[] array syntax with [T] in the test suite
Swift SVN r19192
2014-06-25 23:39:24 +00:00
Ted Kremenek
58558fcca3 Rename 'succ' and 'pred' to 'successor' and 'predecessor' respectively.
This is motivated by <rdar://problem/17051606>.

This ends up renaming variables as well, which seems right for
consistency since we use "predicate" as variable name.

Swift SVN r19135
2014-06-24 19:27:19 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Jordan Rose
1aab6d4687 Derive protocol conformances for types declared in other files in the target.
Normally, protocol conformances are only checked for types and extensions
declared in the current file. However, for protocols that can derive their
conformances (like RawRepresentable), other files in the target might
expect to be able to use the protocol members (like toRaw), which aren't
written in the source. Force the derivation if this is the case.

Also, move the /other/ set of RawRepresentable tests from test/Parse to
test/Sema.

<rdar://problem/15936403>

Swift SVN r14162
2014-02-20 19:47:42 +00:00