Commit Graph

46 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
4132aa04f9 [Tests] NFC: Update all of the test-cases improved by changes to generic argument mismatch handling 2025-06-03 00:49:06 -07: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
Anthony Latsis
f76f6acbf0 Revert "Sema: Emit diagnostics when walking into collection literals with defaulted types"
This reverts commit f608802cfe.
2023-04-20 21:55:40 +03: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
e57359a5c7 Merge pull request #60591 from AnthonyLatsis/migrate-test-suite-to-gh-issues-4
Gardening: Migrate test suite to GH issues p. 4
2022-08-20 04:53:15 +03:00
Anthony Latsis
7fc8377e1c Gardening: Migrate test suite to GH issues: Constraints (1/5) 2022-08-17 15:21:51 +03:00
Sima Nerush
f608802cfe Sema: Emit diagnostics when walking into collection literals with defaulted types
Resolves https://github.com/apple/swift/issues/60011

Gardening: clean up `checkTypeDefaultedCollectionExpr` function
2022-08-15 22:45:21 -06: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
3b54fdb7f6 [TypeChecker] NFC: Add a test-case for expression affected by rdar://61749633 2021-05-04 14:58:41 -07:00
Pavel Yaskevich
fdc535a691 [ConstraintSystem] Don't include self-recursive dynamic member results as "inaccessible"
Solver has to keep track of excluded dynamic member results while
performing lookup because otherwise, in diagnostic modem it might
include such results as inaccessible.

Resolves: rdar://problem/61084565
2020-03-31 16:20:20 -07:00
Pavel Yaskevich
b7a732e625 [Diagnostics] NFC: Add a couple of examples of requirement failures related to generic subscripts 2019-09-13 22:35:53 -07:00
Pavel Yaskevich
a1643d94f7 [Diagnostics] NFC: Update all of the improved test-cases 2019-09-13 22:35:52 -07:00
Brent Royal-Gordon
7ae331dbca [NFC] Pick a few nits for Jordan 2019-04-10 23:17:04 -07:00
Brent Royal-Gordon
c37fee1719 Add parallel tests for static subscripts
This commit modifies various subscript-related test files to add static subscript equivalents of existing tests.
2019-04-10 23:17:04 -07:00
Nate Cook
968783f66c Revise error for incorrect subscript parameters. (#22713)
* Revise error for incorrect subscript parameters.

We use subscripts for more than just indexes in Swift these days, so
the error message needs to be a bit more general.

* Use the term 'argument' instead of 'value'
2019-03-07 18:10:01 -06:00
Nate Cook
5bd2b3e639 Use the term 'argument' instead of 'value' 2019-03-05 08:31:42 -06:00
Doug Gregor
c6631ec83d [Constraint solver] Match call arguments for subscripts.
Record the argument labels provided to a subscript in the solver, and
use that to filter out subscript declarations with non-matching
argument labels during function application. This reduces the number of
overloaded subscript declarations that will be considered in later
steps in the solver, reducing the solution space.

*Disable* this optimization in the normal member-lookup path, which is
intended to go away in the near future. This limits the scope of the
change somewhat, so we can separately tackle the diagnostics issue.
The one diagnostics change here is probably an improvement, because
the user explicitly stated the argument labels, and is more likely
missing a conversion on the argument than having typed the wrong
label.
2019-03-01 09:18:53 -08:00
Nate Cook
faa3d1d75a Merge branch 'master' into nc_subscript_message 2019-02-22 10:57:42 -06:00
Pavel Yaskevich
d4b67bf3f7 [Diagnostics] Improve argument labeling diagnostics
Extend new labeling diagnostics (via fixes) to support
member references and subscripts.
2019-02-21 16:42:56 -08:00
Nate Cook
e32ad7830a Revise error for incorrect subscript parameters.
We use subscripts for more than just indexes in Swift these days, so
the error message needs to be a bit more general.
2019-02-15 15:25:50 -06:00
Pavel Yaskevich
17b04ba800 [ASTVerifier] Fix pre-check to look at subscript arguments
`array-to-pointer` and other conversions are not restricted to apply
expressions, (dynamic) subscript arguments have them too, which
verifier has to support.

Resolves: rdar://problem/45825806
2018-11-06 00:28:44 -08:00
Pavel Yaskevich
37ba52c03d [CSDiagnostics] Diagnose attempt to pass inout argument to a subscript
Tweak `PreCheckExpression` to diagnose calls to subscript with
`&` arguments, which is not allowed.

Resolves: rdar://problem/45819956
2018-11-05 16:15:59 -08:00
Pavel Yaskevich
63b802ca88 [AST/Printing] Don't omit empty labels in special names
This makes diagnostics more verbose and accurate, because
it's possible to distinguish how many parameters there are
based on the message itself.

Also there are multiple diagnostic messages in a format of
`<descriptive-kind> <decl-name> ...` that get printed as
e.g. `subscript 'subscript'` if empty labels are omitted.
2018-09-24 18:36:53 -07:00
Pavel Yaskevich
89c104b709 [QoI] Improve diagnostics for subscript with invalid index arguments
In `FailureDiagnosis::visitSubscriptExpr` if there is only a single
candidate available, verify that the problem is actually related
to the contextual mismatch by type-checking whole subscript without
contextual info, if that returns a type - it's contextual, otherwise
diagnose as incorrect argument type problem.

Resolves: rdar://problem/31977679
2017-05-21 21:56:43 -07: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
Pavel Yaskevich
4a60a53b19 [Diagnostics] Fix bad diagnostic for failed assignment from Any to a more specific type
When generating constraints for subscript convert InOutType into LValueType,
because base of the subscript should never be marked as inout, but rather as
@lvalue to denote mutability.

Resolves <rdar://problem/25601561>.
2016-10-04 16:23:05 -07:00
Doug Gregor
22287ddb58 [Type system] Infer 'Any' for array elements and dictionary values and 'AnyHashable' for dictionary keys.
The id-as-Any work regressed cases where Swift code could specify
heterogeneous collection literals, e.g.,

    var states: [String: Any] = [
      "California": [
        "population": 37_000_000,
        "cities": ["Los Angeles", "San Diego", "San Jose"],
      ],
      "Oregon": [
        "population": 4_000_000,
        "cities": ["Portland", "Salem", "Eugene"],
      ]
    ]

Prior to this, the code worked (when Foundation was imported) because
we'd end up with literals of type [NSObject : AnyObject].

The new defaulting rule says that the element type of an array literal
and the key/value types of a dictionary literal can be defaulted if no
stronger type can be inferred. The default type is:

  Any, for the element type of an array literal or the value type of a
  dictionary literal, or

  AnyHashable, for the key type of a dictionary literal.

The latter is intended to compose with implicit conversions to
AnyHashable, so the most-general inferred dictionary type is
[AnyHashable : Any] and will work for any plausible dictionary
literal.

To prevent this inference from diluting types too greatly, we don't
allow this inference in "top-level" expressions, e.g.,

  let d = ["a" : 1, "b" : "two"]

will produce an error because it's a heterogeneous dictionary literal
at the top level. One should annotate this with, e.g.,

  let d = ["a" : 1, "b" : "two"] as [String : Any]

However, we do permit heterogeneous collections in nested positions,
to support cases like the original motivating example.

Fixes rdar://problem/27661580.
2016-08-04 20:58:13 -07:00
Chris Lattner
fb7a4e9ded Generalize the closure work from yesterday, enough to fix:
rdar://17687826 - QoI: error message when reducing to an untyped dictionary isn't helpful
2016-07-31 15:25:17 -07: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
Chris Lattner
cf2e7f6f45 Fix SR-718: Type mismatch reported as extraneous parameter
The issue here is that the constraint solver was deciding on
FixKind::RelabelCallTuple as the fix for the problem and emitting the
diagnostic, even though there were two different fixes possible.

CSDiags has the infrastructure to support doing doing the right thing
here, but is only being used for ApplyExprs, not SubscriptExprs.

The solution is to fix both problems: remove FixKind::RelabelCallTuple,
to let CSDiags handle the problem, and enhance CSDiags to treat
SubscriptExpr more commonly with ApplyExpr.  This improves several cases
where the solver was picking one solution randomly and suggesting that
as a fix, instead of listing that there are multiple different solutions.
2016-02-12 17:19:54 -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
Chris Lattner
a5a988e726 Fix rdar://22509125 QoI: Error when unable to infer generic archetype lacks greatness
Rearrange diagnoseGeneralConversionFailure to diagnose structural problems
even if we have some UnresolvedTypes floating around, then reject constraint
failures with UnresolvedTypes in them even harder.  This keeps us giving
good errors about failures where we have a structural problem (with buried
irrelevant details) while not complaining about cases that are actually
ambiguous.

The end result of this is that we produce a lot better error messages in the
case of failed archetype inference.  This also highlights the poor job we do
handling multi-stmt closureexprs...
2016-01-11 20:45:11 -08:00
Slava Pestov
f6e4355b69 Sema: Fix monthly TypeNullifier bug
This time, the issue is that TypeNullifier skips bodies of
multi-statement closures. However, ExprRewriter will type
happily pass them on to typeCheckClosureBody(). This could
trigger assertions. Fix this by skipping type checking of
multi-statement closures when diagnosing.

There seems to be a minor QoI regression in some test cases
that already looked pretty dodgy and/or had FIXMEs. However
I think its worth fixing a crash.
2015-12-11 08:58:52 -08:00
Chris Lattner
4ebb461d63 Fix: <rdar://problem/23670252> QoI: Misleading error message when assigning a value from [String : AnyObject]
This teaches SubscriptExpr diagnostics to substitute the base type of a
subscript expr through the generic argument types, resolving achetypes in
common situations to concrete types.  We previously complained:

  error: cannot subscript a value of type '[String : AnyObject]' with an index of type 'String'

which is completely wrong, we now produce the correct error:

  error: cannot assign value of type 'AnyObject?' to type 'String?'
2015-12-07 17:28:16 -08:00
Chris Lattner
6636bafadf Fix <rdar://problem/23272739> Poor diagnostic due to contextual constraint
Previously we erroneously complained:
  error: cannot invoke 'contains' with an argument list of type '(String)'
now we correctly complain:
  error: unexpected non-void return value in void function

This enhances CSDiags to use "getTypeOfMember" when analyzing method
candidates that are applied to a known base type.  Using it allows us to
substitute information about the base, resolving archetypes that exist in
subsequent argument positions.  In the testcase, this means that we use
information about Set<String> to know that the argument to "contains" is a
String.

This allows us to generate much better diagnostics in some cases, and works
around some limitations in the existing stuff for handling unresolved
archetypes.  One unfortunate change is the notes in Misc/misc_diagnostics.swift.
Because we don't track argument lists very well, we are flattening an argument
list that is actually ((Int,Int)) into (Int, Int) so we get a bogus looking
diagnostic.  This was possible before this patch though, it is just one
more case that triggers the issue.
2015-12-01 21:22:24 -08:00
David Farler
93b6962478 Warn when using 'var' bindings in function parameters
These will no longer be allowed in a future Swift release.

rdar://problem/23172698
2015-11-03 17:24:20 -08:00
Chris Lattner
778d8d67e6 Use isUnresolvedOrTypeVarType more generally, and fix a crash on the new testcase, handling
unresolved subscript bases.


Swift SVN r31698
2015-09-04 23:03:11 +00:00
Chris Lattner
bb35cbcd38 Teach CSDiag how to resolve SubscriptMember locators, fixing
<rdar://problem/21364448> QoI: Poor error message for ambiguous subscript call

and improving several other subscript-related diagnostics.



Swift SVN r31082
2015-08-07 20:00:32 +00:00
Chris Lattner
6dc013ac8e testcase showing a poor diagnostic.
Swift SVN r31080
2015-08-07 19:45:15 +00:00
Chris Lattner
e4b6afb9ae Start moving the testsuite to the "_ = foo()" idiom for evaluating an
expression but ignoring its value.  This is the right canonical way to do
this.  NFC, just testsuite changes.



Swift SVN r28638
2015-05-15 20:15:54 +00:00
Chris Lattner
4366da9250 more testcase updates for upcoming diagnostics change.
Swift SVN r28409
2015-05-11 06:05:00 +00: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
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
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Doug Gregor
1ea5b4d801 [Constraint application] Start weaning us from semaSubscriptExpr().
Handle the application of SubscriptExprs directly in constraint
application. This is the easy case.


Swift SVN r5147
2013-05-10 18:25:32 +00:00