Commit Graph

80 Commits

Author SHA1 Message Date
Kathy Gray
84ef25afbc Migrate to calling interfaceType and remove SelfParam
Migrate more tests
2025-10-10 17:46:22 +01:00
Kathy Gray
5e407bce89 Diagnostics change for ambiguous overloads previously specifying 'this'
Updates the message to use the type or ValueDecl instead of this on previous 'Found this candidate' messages
Note: doees not yet change all test cases so more tests are failing

Improve Diagnostic message on overload ambiguitiy

Remove messages that say 'found this candidate' in favour of providing the type for the candidate to aid in selection when the candidates are presented in a dialogue window.

Fix more tests
2025-10-10 17:46:22 +01:00
fummicc1
4dda7efc0f [AST] Improve diagnostics message for swift users.
Use `initializer` instead of `constructor` because it is more official word to express its meaning.
2024-03-27 12:32:25 +09:00
Pavel Yaskevich
d7a41c2aff [CSFix] Diagnose an invalid member reference in ambiguous contexts
For example @objc lookup could find multiple instance members
on `AnyObject`. It should be allowed to diagnose issues with
that as non-ambiguous if all fixes have the same kind/base type.

Resolves: rdar://102412006
2023-03-20 15:15:55 -07:00
Anthony Latsis
4d2b2f6fee Sema: Allow member type expressions rooted on non-identifier qualifiers to omit .self until Swift 6 2023-03-09 04:55:25 +03:00
Anthony Latsis
7fc8377e1c Gardening: Migrate test suite to GH issues: Constraints (1/5) 2022-08-17 15:21:51 +03:00
Anthony Latsis
324913055d CS: Handle unbound references to @objc optional methods 2022-03-30 19:11:29 +03:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Hamish Knight
a84833bfea [test] Add AnyObject construction test case
This is a case where a constructor overload choice
might currently have an optional opened type, so
make sure we can handle it. Arguably we shouldn't
even be introducing constructors into the overload
set here though, as it's invalid anyway.
2021-09-28 12:13:33 +01:00
Hamish Knight
5c01efa478 [test] Add a couple of IUO test cases 2021-09-28 12:13:33 +01:00
Pavel Yaskevich
66815f9d25 [MiscDiagnostics] Downgrade plain type use error to a warning for certain positions
In Swift < 6 warn about plain type name passed as an
argument to a subscript, dynamic subscript, or ObjC
literal since it used to be accepted.

Resolves: rdar://80270126
2021-07-07 14:36:29 -07:00
Pavel Yaskevich
6080a40cff [TypeChecker] NFC: Run Constraints/dynamic_lookup.swift on all supported platforms
Resolves: rdar://64425653
2021-04-05 17:31:58 -07:00
Luciano Almeida
d55eed46e8 [Sema][CSApply] Moving some checked cast diagnostics to a fix format (#34980)
* [Sema] Implementing is runtime check always true diagnostic as a fix

* [AST] Implement getWithoutThrows on function type

* [CSSimplify] Detect that checked cast types conversion is always true and record warning fix

* [test] Some additional test cases for SR-13789

* [Sema] Fixing typo on fix name

* [Sema] Move and adjust the ConditionalCast diagnostics to the fix format

* [Sema] Remove some checked cast diagnostics from check constraints and move to fix

* [Sema] Renaming checked cast coercible types fix

* [Sema] Some adjustments and rewrite on the logic for downcast record fix

* [Sema] Move logic of runtime function type to AllowUnsupportedRuntimeCheckedCast::attempt

* [Sema] Abstract checked cast fix logic to static function and minor adjustments

* [Sema] Renamings from review
2021-02-10 08:31:06 -03:00
Hamish Knight
b5e39974c5 Temporarily disable dynamic_lookup.swift for non-macOS 2020-06-16 16:01:32 -07:00
Pavel Yaskevich
d9594c712a [TypeChecker] NFC: Adjust tests improved by new approach for ambiguity diagnosis 2020-06-12 11:47:03 -07:00
Hamish Knight
dad8f13f6e [Sema] Eliminate a subscript AnyObject lookup ambiguity
Previously we would always consider an AnyObject
subscript lookup to be ambiguous if there was a
candidate in both a class and protocol, even if
the selectors and types matched. This was due to
the protocol's generic signature preventing the
signatures from being coalesced.

Tweak the logic to strip generic signatures when
comparing for AnyObject lookup, matching what we
do for @objc methods.

Resolves SR-8611.
Resolves rdar://43645564 & rdar://62906344.
2020-05-12 21:23:34 -07:00
Hamish Knight
12b9426312 [Sema] Don't diagnose DynamicSubscriptExpr's arg as tuple
Register DynamicSubscriptExpr's index expression
as a call argument in MiscDiagnostics to avoid it
being diagnosed as a single element labelled tuple.

Resolves SR-12799.
2020-05-12 21:23:33 -07:00
Suyash Srijan
543d649278 [Diagnostics] Warn when the result of a Void-returning function is ignored (by assigning into '_') (#29576) 2020-02-04 20:19:37 +00:00
Slava Pestov
1df3d1a33c Frontend: Don't interleave parsing and typechecking for the main file
SIL files still require this behavior; if we cleaned that up we
could simplify a fair bit of code here.

Fixes <https://bugs.swift.org/browse/SR-284>,
<https://bugs.swift.org/browse/SR-4426>.
2019-12-05 08:45:55 -05:00
Hamish Knight
4d8e612493 [CS] Prevent callAsFunction from being used on AnyObject
Previously this hit an assertion in CSApply.
While we could technically make it work, it's
probably best not to allow it.

Resolves SR-11829.
2019-12-02 15:29:21 -08:00
Hamish Knight
9d80a82939 Make resolveLocatorToDecl simpler and more robust
Rather than attempting to pull out a concrete decl
ref from the rewritten function expr, retrieve the
callee from the solution using a callee locator
computed before the apply is rewritten, and then
pass this callee down through `finishApply` and
`coerceCallArguments`.

Resolves SR-11648.
2019-10-22 11:54:04 -07:00
Pavel Yaskevich
688042becf [Diagnostics] Add inaccessible member diagnostic 2019-03-18 13:48:08 -07:00
Pavel Yaskevich
202234f325 [CSDiagnostics] Diagnose invalid optional unwrap via fixes
Detect and fix situations when (force) unwrap is used on
a non-optional type, this helps to diagnose invalid unwraps
precisely and provide fix-its.

Resolves: [SR-8977](https://bugs.swift.org/browse/SR-8977)
Resolves: rdar://problem/45218255
2018-12-05 08:10:07 -08:00
Mark Lacey
ea0050891a Merge pull request #18951 from hamishknight/concrete-is-better-swift5
[CSRanking] Favour concrete members over protocol requirements in Swift 5 mode
2018-08-29 22:32:08 -07:00
gregomni
13d02bb85c Make the rvalue-as-lvalue fix symmetric for bind constraints, which causes another set of assignment errors to be discovered in
the CS and slightly reduces the code in CSDiag.
2018-08-29 19:07:29 -07:00
Hamish Knight
b72d7e2cf9 Merge remote-tracking branch 'upstream/master' into concrete-is-better-swift5 2018-08-29 13:57:34 +01:00
gregomni
821f63fe98 Make assignments and assignment failure diagnoses directly in the CS.
More specific diagnoses for assigning to read-only keypaths.
'computeAssignDestType' is dead code now.
ConstraintFix shouldRecordFix()
2018-08-24 20:39:03 -07:00
Hamish Knight
1912d289e1 [CSRanking] Exclude concrete-over-protocol rule from dynamic lookup ranking
This rule caused us to lose ambiguities in places where we really want ambiguity for `AnyObject` lookup, so only apply it when not comparing such overloads. This whole situation is a bit of a hack – really we shouldn't be applying any type-based or context-based overload ranking rules to overloads found through `AnyObject` lookup, but unfortunately we don't have syntax to precisely disambiguate overloads.

This commit can be reverted if/when we ever remove `AnyObject` lookup.
2018-08-24 15:50:28 +01:00
Hamish Knight
1520dbbf46 [test] Expand AnyObject ambiguity test to cover methods and subscripts 2018-08-24 15:50:27 +01:00
Hamish Knight
27706321ec Add test for dynamic member lookup behaviour changed by #15412 2018-08-15 23:18:38 +01:00
Pavel Yaskevich
84cd99a3eb [Diagnostics] Enable extraneous/incorrect label diagnostics via solver fixes
This builds on initial commit which added `RelabelArguments` fix
to the solver that only supported `missingLabels` at that moment,
but now it supports all three posibilities - missing/extraneous and
incorrect labels.
2018-07-25 14:34:26 -07:00
Slava Pestov
7a98297e79 Sema: Fix crash when diagnosing failed dynamic lookup of 'init'
Fixes <rdar://problem/39818322>.
2018-05-04 23:36:50 -04:00
fischertony
ba1bbd028d updated missed tests 2018-04-22 20:48:24 +03:00
Doug Gregor
d20bcf14c2 [Type checker] Prefer available declarations in AnyObject lookup.
When we perform AnyObject lookup, we can find multiple declarations with
the same signature. When we do so, we pick fairly arbitrarily among them.
However, make sure that we don’t pick an unavailable declaration when
an available declaration is… available.

Fixes rdar://problem/39115471.
2018-04-05 14:44:13 -07:00
Mark Lacey
f08823757a IUO: Generate Optional<T> rather than ImplicitlyUnwrappedOptional<T>.
Stop creating ImplicitlyUnwrappedOptional<T> so that we can remove it
from the type system.

Enable the code that generates disjunctions for Optional<T> and
rewrites expressions based on the original declared type being 'T!'.

Most of the changes supporting this were previously merged to master,
but some things were difficult to merge to master without actually
removing IUOs from the type system:
- Dynamic member lookup and dynamic subscripting
- Changes to ensure the bridging peephole still works

Past commits have attempted to retain as much fidelity with how we
were printing things as possible. There are some cases where we still
are not printing things the same way:
- In diagnostics we will print '?' rather than '!'
- Some SourceKit and Code Completion output where we print a Type
  rather than Decl.

Things like module printing via swift-ide-test attempt to print '!'
any place that we now have Optional types that were declared as IUOs.

There are some diagnostics regressions related to the fact that we can
no longer "look through" IUOs. For the same reason some output and
functionality changes in Code Completion. I have an idea of how we can
restore these, and have opened a bug to investigate doing so.

There are some small source compatibility breaks that result from
this change:
- Results of dynamic lookup that are themselves declared IUO can in
  rare circumstances be inferred differently. This shows up in
  test/ClangImporter/objc_parse.swift, where we have
    var optStr = obj.nsstringProperty
  Rather than inferring optStr to be 'String!?', we now infer this to
  be 'String??', which is in line with the expectations of SE-0054.
  The fact that we were only inferring the outermost IUO to be an
  Optional in Swift 4 was a result of the incomplete implementation of
  SE-0054 as opposed to a particular design. This should rarely cause
  problems since in the common-case of actually using the property rather
  than just assigning it to a value with inferred type, we will behave
  the same way.
- Overloading functions with inout parameters strictly by a difference
  in optionality (i.e. Optional<T> vs. ImplicitlyUnwrappedOptional<T>)
  will result in an error rather than the diagnostic that was added
  in Swift 4.1.
- Any place where '!' was being used where it wasn't supposed to be
  allowed by SE-0054 will now treat the '!' as if it were '?'.
  Swift 4.1 generates warnings for these saying that putting '!'
  in that location is deprecated. These locations include for example
  typealiases or any place where '!' is nested in another type like
  `Int!?` or `[Int!]`.

This commit effectively means ImplicitlyUnwrappedOptional<T> is no
longer part of the type system, although I haven't actually removed
all of the code dealing with it yet.

ImplicitlyUnwrappedOptional<T> is is dead, long live implicitly
unwrapped Optional<T>!

Resolves rdar://problem/33272674.
2018-01-31 12:15:58 -08:00
Mark Lacey
c94246d876 Add more dynamic lookup tests.
We weren't previously testing every combination of dynamic with and
without IUO, so I've added tests to attempt to improve the situation.

We currently produce rvalues for dynamic lookups, which is incorrect,
and can be seen in some of the test output.
2018-01-15 18:09:04 -08:00
Dmitri Gribenko
486cab447d tests: replace 'rm -rf %t && mkdir -p %t' with '%empty-directory(%t)'
These changes were made using a script.
2017-06-04 11:08:39 -07:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Doug Gregor
7dd1c87dd3 [SE-0160] Warn about uses of @objc declarations that used deprecated @objc inference.
When in Swift 3 compatibility mode without
`-warn-swift3-objc-inference`, warn on the *uses* of declarations that
depend on the Objective-C runtime that became `@objc` due to the
deprecated inference rule. This far more directly captures important
uses of the deprecated Objective-C entrypoints. We diagnose:

* `#selector` expressions that refer to one of these `@objc` members
* `#keyPath` expressions that refer to one of these `@objc` members
* Dynamic lookup (i.e., member access via `AnyObject`) that refers to
  one of these `@objc` members.
2017-03-31 21:22:15 -07:00
Rintaro Ishizaki
384ab780e9 [Diagnostic verifier] Make '<unknown>' check optional
Added frontend option '-verify-ignore-unknown'
2017-02-02 10:49:32 +09:00
Rintaro Ishizaki
827c6e7c3d [Diagnostic verifier] Diagnostics at '<unknown>:0' are unexpected 2017-02-02 10:48:54 +09:00
Mark Lacey
ecedb337e7 [Sema] In simplifyType, if substitution fails retry with IUOs stripped.
We can end up with IUOs bound as a result of overload resolution. When
this happens and the resulting type is used as a generic, we can end up
with dependent member types that fail to simplify properly as a result
of failing to substitute due to the IUO getting in the way. In these
cases it should be completely safe to strip the IUO off and retry
substitution with the base type.

This isn't really an ideal fix by any means, and we need to revisit how
we handle bindings to make it more uniform, but for now I think this is
a reasonable path to move forward.

Fixes a source compatibility regression.

rdar://problem/29960575
2017-01-31 23:52:29 -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
Mark Lacey
4f5b80dd03 Make fix for dynamic lookup on Any work for more general expressions.
Follow-up to 56a5ef00a4.

Thanks to Jordan for noticing and suggesting this!

rdar://problem/27639935
2016-08-08 12:59:56 -07:00
Mark Lacey
56a5ef00a4 Add a fixit for attempting member lookup on Any.
Suggest casting to AnyObject or a more specific type.

rdar://problem/27639935
2016-08-07 12:19:53 -07:00
Robert Widmann
4f465224ea Polish off uses of dynamicType in tests 2016-07-29 16:59:14 -07:00
David Farler
7bfaeb57f1 [SE-0081] Warn on deprecated where clause inside angle brackets
and provide a fix-it to move it to the new location as referenced
in SE-0081.

Fix up a few stray places in the standard library that is still using
the old syntax.

Update any ./test files that aren't expecting the new warning/fix-it
in -verify mode.

While investigating what I thought was a new crash due to this new
diagnostic, I discovered two sources of quite a few compiler crashers
related to unterminated generic parameter lists, where the right
angle bracket source location was getting unconditionally set to
the current token, even though it wasn't actually a '>'.
2016-07-26 01:41:10 -07:00
Joe
a6dad0091b [SE-0095] Initial parsing implementation for '&' composition syntax
This commit defines the ‘Any’ keyword, implements parsing for composing
types with an infix ‘&’, and provides a fixit to convert ‘protocol<>’

- Updated tests & stdlib for new composition syntax
- Provide errors when compositions used in inheritance.
Any is treated as a contextual keyword. The name ‘Any’
is used emit the empty composition type. We have to
stop user declaring top level types spelled ‘Any’ too.
2016-07-19 12:01:02 -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