Commit Graph

106 Commits

Author SHA1 Message Date
Slava Pestov
908c9368ed Parse: Only accept certain literals as enum case raw values
Just checking for LiteralExpr is too broad, because Sema doesn't
know what to do with RegexLiteralExpr for example.
2025-06-17 09:19:00 -04:00
Allan Shortlidge
16de339051 AST: Enable -unavailable-code-optimization for zippered libraries.
Correct the determination of whether a declaration is unreachable at runtime
when compiling a zippered library.

Resolves rdar://125930716.
2025-02-09 11:20:48 -08:00
Tony Allevato
4902e69ee1 Merge pull request #76331 from allevato/ast-printer-fixes
[ASTPrinter] Fix missing operators in synthesized `==` impls printed by `-print-ast`.
2024-11-12 07:46:32 -05:00
Dylan Sturgeon
a1e888785d Enable indexing for refs to synthesized declarations.
Based on feedback in PR https://github.com/swiftlang/swift/pull/69460, enabling indexing for synthesized decls because they are usable by users and make sense to appear in the indexstore.

Sets `synthesized` on some additional decls:

  - derived `hashInto(...)`
  - Objc properties and methods derived from Objc protocols

https://github.com/apple/swift/issues/67446
2024-10-28 10:07:27 -07:00
Tony Allevato
aebe2ab309 Fix missing operators in synthesized == impls printed by -print-ast.
`visitBinaryExpr` wasn't handling `UnresolvedDeclRefExpr` nodes, which the
synthesized `==` implementation uses to compare fields/payloads. Also fixed
the test that wasn't catching it since it also left out the operators.
2024-09-07 20:13:13 -04:00
Ben Langmuir
fd1875dcfb [test] Move availability tests to later fake OS versions
10.50 was once greater than any real macOS version, but now it compares
less than real released versions, which makes these tests depend on the
deployment target unnecessarily. Update these tests to use even larger
numbers to hopefully keep them independent a little longer.
2024-08-21 11:38:54 -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
Allan Shortlidge
14200e412c SILGen/stdlib: Remove _diagnoseUnavailableCodeReached_aeic().
It should no longer be necessary to provide an `@_alwaysEmitIntoClient` version
of `_diagnoseUnavailableCodeReached()`. This workaround was originally added to
provide compatibility with projects that were misconfigured to compile against
a newer stdlib but link against an older one.

Resolves rdar://119892482.
2024-07-11 14:53:03 -07:00
Nate Chandler
2eea24cd35 [TypeCheckAttr] Frozen is valid without resilience
Even when building not for library evolution, @frozen is a valid
attribute on enums.

rdar://128358780
2024-05-20 17:22:47 -07:00
Allan Shortlidge
feba547411 AST: Adopt Decl::isUnreachableAtRuntime() in Hashable/Equatable derivation.
When deriving `Hashable` and `Equatable` for enums, use
`Decl::isUnreachableAtRuntime()` to determine whether or not to insert
`_diagnoseUnavailableCodeReached()` traps for specific enum elements. This
fixes a bug where inappropriate traps were inserted for enum elements that are
unavailable for app extensions. It also fixes a bug where traps were inserted
when building a zippered library for macOS and enum elements were unavailable
on macOS but not for macCatalyst clients.

Resolves rdar://125371621
2024-04-04 16:18:35 -07:00
Doug Gregor
a51a172035 Make a few tests independent of the default diagnostic style 2024-02-19 02:48:36 -10:00
Rajveer
48847da5e6 Added the expression cases of the form 'visit...Expr()'
Part of Issue #61601
2024-02-02 13:51:37 +05:30
Allan Shortlidge
6d22433d0f AST/SILGen: Use @_alwaysEmitIntoClient diagnostic helper in unavailable code.
The `_diagnoseUnavailableCodeReached()` function was introduced in the Swift
5.9 standard library and employs `@backDeployed` to support compilation of
binaries that target OS releases aligned with earlier Swift releases.
Unfortunately, though, this backdeployment strategy doesn't work well for some
unusual build environments. Specifically, in some configurations code may be
built with a compiler from a recent Swift toolchain and then linked against the
dylibs in an older toolchain. When linking against the older dylibs, the
`_diagnoseUnavailableCodeReached()` function does not exist but the
`@backDeployed` thunks emitted into the binary reference that function and
therefore linking fails.

The idea of building with one toolchain and then linking to the dylibs in a
different, older toolchain is extremely dubious. However, it exists and for now
we need to support it. This PR introduces an alternative
`_diagnoseUnavailableCodeReached()` function that is annotated with
`@_alwaysEmitIntoClient`. Calls to the AEIC variant are now emitted by the
compiler when the deployment target is before Swift 5.9.

Once these unusual build environments upgrade and start linking against a Swift
5.9 toolchain or later we can revert all of this.

Resolves rdar://119046537
2023-12-19 16:26:56 -08:00
Harlan Haskins
4ac34a40ea @retroactive conformance syntax and checking (#36068) 2023-10-20 14:27:03 -07:00
Minhyuk Kim
c0eab4f551 Change error message to specify when inout usage is allowed 2023-09-24 23:18:27 +09:00
Allan Shortlidge
e4810f5304 Sema: Fix unavailable enum element cases in derived hashable/equatable impls.
When deriving the `hash(into:)` and `==` witnesses for `Hashable`/`Equatable`
enums, call `_diagnoseUnavailableCodeReached()` in the case bodies for
unavailable enum elements. This is needed because the previously derived code
would operate on the values associated with unavailable enum elements, which is
illegal if the types of those associated values are also unavailable (these
case bodies would have failed typechecking had they been hand-written). The new
structure also more explicitly documents that reaching these cases is
unexpected, since unavailable enum elements should not be instantiated at run
time.
2023-07-31 22:44:52 -07:00
Allan Shortlidge
5c2534372a NFC: Add basic -print-ast tests for derived hashable/equatable conformances. 2023-07-31 21:27:46 -07: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
Harlan Haskins
26b20ef198 Merge pull request #28227 from keith/ks/remove-frozen-warning
Remove warning about @frozen without library evolution
2019-11-15 20:14:24 -08:00
swift-ci
05405351b7 Merge pull request #28274 from DougGregor/bool-raw-value 2019-11-14 21:52:10 -08:00
Doug Gregor
21a7fba895 More tests for Bool raw values of enums 2019-11-14 17:22:09 -08:00
Doug Gregor
9243c61244 Handle Boolean literals as enum raw values.
Fixes rdar://problem/55384273.
2019-11-14 17:22:09 -08:00
Keith Smiley
bf4aaacb02 Remove @frozen without library evolution warning
This warning is produced if you annotate an enum with `@frozen` but
build without library evolution enabled. The problem is that if you
only build with library evolution enabled for release builds, this
leaves you with a warning for all debug builds. The downside of this
change is that if you never build with library evolution, you may have
this unnecessary annotation without noticing.
2019-11-12 19:35:05 -08:00
Robert Widmann
b8dc4f0a3f Use TypeCheckerOptions to simplify FunctionBodyTimer 2019-11-12 09:56:02 -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
Robert Widmann
d6fe1e9d39 Teach IRGen to Emit Invalid @objc Enums
In order to remove the enum raw value check request in validateDecl,
IRGen must now tolerate recieving an invalid raw value expression.
Switch the assert to instead check for this condition and emit an
invalid negative discriminator.
2019-10-14 15:29:43 -07:00
Pavel Yaskevich
d90117bb8a [Diagnostics] Remove argument handling from conformance failures
Argument-to-Parameter mismatch handles conformance failures
related to arguments, so the logic in `MissingConformanceFailure`
which wasn't entirely correct is now completely obsolete.

Resolves: rdar://problem/56234611
2019-10-14 00:34:37 -07:00
Slava Pestov
6828a12416 Sema: Remove unnecessary circularity breaks 2019-10-03 17:11:45 -04:00
Suyash Srijan
ad4d623818 Merge pull request #27382 from theblixguy/fix/SR-11522
[CSApply] Don't diagnose a 'static let none' as ambiguous none unless its an enum type
2019-09-28 11:14:52 +01: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
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
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
Ben Cohen
e9d4687e31 De-underscore @frozen, apply it to structs (#24185)
* De-underscore @frozen for enums

* Add @frozen for structs, deprecate @_fixed_layout for them

* Switch usage from _fixed_layout to frozen
2019-05-30 17:55:37 -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
Slava Pestov
1159af50d9 Rename -enable-resilience to -enable-library-evolution and make it a driver flag
Fixes <rdar://problem/47679085>.
2019-03-14 22:24:26 -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