Commit Graph

83 Commits

Author SHA1 Message Date
Hamish Knight
2d7500eda6 [AST] Remove ParenType
Today ParenType is used:

1. As the type of ParenExpr
2. As the payload type of an unlabeled single
   associated value enum case (and the type of
   ParenPattern).
3. As the type for an `(X)` TypeRepr

For 1, this leads to some odd behavior, e.g the
type of `(5.0 * 5).squareRoot()` is `(Double)`. For
2, we should be checking the arity of the enum case
constructor parameters and the presence of
ParenPattern respectively. Eventually we ought to
consider replacing Paren/TuplePattern with a
PatternList node, similar to ArgumentList.

3 is one case where it could be argued that there's
some utility in preserving the sugar of the type
that the user wrote. However it's really not clear
to me that this is particularly desirable since a
bunch of diagnostic logic is already stripping
ParenTypes. In cases where we care about how the
type was written in source, we really ought to be
consulting the TypeRepr.
2024-10-31 11:32:40 +00:00
Pavel Yaskevich
9816fffcd3 [Diagnostics] Forgo all restrictions if one side of conversion has invalid use of &
None of the restrictions like existential conversion or optional
promotion would actually match, so there is no point in trying them
just to add more unrelated fixes.

Resolves: rdar://100369066
2023-04-04 18:00:13 -07:00
Doug Gregor
af49a90dde Customize diagnostic text for extra/missing/mislabeled arguments for callee kind
Most of the diagnostics for extra/missing/mislabeled arguments refer
to argument to a "call". Some (but not call) would substitute in
"subscript". None would refer to an argument to a macro expansion
properly.

Rework all of these to refer to the argument in a call, subscript, or
macro expansion as appropriate. Fix up lots of tests that now say
"subscript" instead, and add tests for macro expansions.
2023-01-02 21:22:04 -08:00
Anthony Latsis
7fc8377e1c Gardening: Migrate test suite to GH issues: Constraints (1/5) 2022-08-17 15:21:51 +03:00
Pavel Yaskevich
ff6112024e [CSSimplify] Don't fix invalid r-value use for misplaced &
When `&` is misplaced it creates r-value -> l-value mismatch
in the code which is just a consequence and shouldn't be diagnosed.

Resolves: rdar://96631324
2022-07-12 13:55:04 -07:00
Pavel Yaskevich
a0d132582e [Diagnostics] Improve diagnostic message for extraneous &
Resolves: https://github.com/apple/swift/issues/58389
2022-04-25 15:08:04 -07:00
Pavel Yaskevich
607f49dc2e [TypeChecker] Find outermost paren or tuple while checking invalid inout use
Unwrap `InOutExpr` from all parens until the outermost paren or a tuple
to correctly diagnose calls like `foo(((&bar)))` or `foo(x: (&bar))`,
 and suggest a fix-it with moves `&` outside parens.

Resolves: rdar://problem/71356981
2020-11-19 13:31:10 -08:00
Luciano Almeida
885815227f [tests] Add regression tests for SR-13732 2020-10-16 18:32:30 -03:00
Pavel Yaskevich
b9cf4fa6c2 [Diagnostics] Add a diagnostic for invalid conversion of inout argument/parameter
Since there is no subtyping allowed in `inout` positions, let's
produce a tailored error message and a note about that.
2019-08-28 12:19:02 -07: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
gregomni
9e0dae513c Start changing over rvalue-vs-lvalue errors to be done via constraint system fixes. For this first commit, just handling inout parameter problems. 2018-08-16 17:34:17 -07:00
David Zarzycki
67710606e6 [Parse] Move tok::amp_prefix closer to parameter list logic
The amp_prefix token is currently tolerated in any unary expression
context and then diagnosed later by Sema. This patch changes parsing to
only accept tok::amp_prefix in its allowed position: parameter lists.

This also fixes two "compiler crasher" tests.
2018-03-30 17:56:36 -04:00
David Zarzycki
94a540db4b [Sema] NFC: More TVO_CanBindToInOut removal
If we're willing to tolerate less specific diagnostics, then we can
remove more instances of TVO_CanBindToInOut. After this change, there is
only one client of TVO_CanBindToInOut.
2018-03-30 09:22:37 -04:00
Robert Widmann
1d6f11ab54 Refactor ArrayExpr visitor for better QoI
Also remove mention of the word “contextual” type from the diagnostic
that rewrites array literals into dictionary literals and scale back
the scope of the diagnostic.  This method was catching and
mis-diagnosing too many errors that could better be handled by invalid
conversion diagnostics.
2017-12-15 18:20:36 -05:00
Slava Pestov
427bb321a4 Sema: Fix crash when diagnosing invalid assignment expression
CSGen can see an AssignExpr where the destination has an
unresolved type, even in a case where no diagnostic has been
emitted yet.

It is then wrong to return an empty type from here, because
this stops us from attempting to solve the expression, which
results in no diagnostic being emitted in the end.

The test case I added produces a decent diagnostic now,
but the original one in the radar now just says 'ambiguous
without more context'. Still, better than crashing.

Fixes <rdar://problem/30685195>.
2017-05-05 23:54:23 -07: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
3522f3c47c Fixing tests with artihmetic operators back on concrete types 2017-01-23 14:56:29 -08:00
Max Moiseev
70b2343626 Merge branch 'master' into new-integer-protocols 2016-11-28 15:25:01 -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
Dave Abrahams
d4030a9715 [stdlib] Fix constraint tests for new integers 2016-07-29 18:30:24 -07:00
Doug Gregor
b9363fe6bd [SE-0111] Enable SE-0111 by default. 2016-07-29 17:28:24 -07:00
Andrew Trick
0b75ee975e Remove "illegal" UnsafePointer casts from the stdlib.
Update for SE-0107: UnsafeRawPointer

This adds a "mutating" initialize to UnsafePointer to make
Immutable -> Mutable conversions explicit.

These are quick fixes to stdlib, overlays, and test cases that are necessary
in order to remove arbitrary UnsafePointer conversions.

Many cases can be expressed better up by reworking the surrounding
code, but we first need a working starting point.
2016-07-28 20:42:23 -07:00
Andrew Trick
a18d490d6a Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3773)
* Migrate from `UnsafePointer<Void>` to `UnsafeRawPointer`.

As proposed in SE-0107: UnsafeRawPointer.

`void*` imports as `UnsafeMutableRawPointer`.
`const void*` imports as `UnsafeRawPointer`.

Occurrences of `UnsafePointer<Void>` are replaced with UnsafeRawPointer.

* Migrate overlays from UnsafePointer<Void> to UnsafeRawPointer.

This requires explicit memory binding in several places,
particularly in NSData and CoreAudio.

* Fix a bunch of test cases for Void->Raw migration.

* qsort takes IUO values

* Bridge `Unsafe[Mutable]RawPointer as `void [const] *`.

* Parse #dsohandle as UnsafeMutableRawPointer

* Update a bunch of test cases for Void->Raw migration.

* Trivial fix for the SceneKit test case.

* Add an UnsafeRawPointer self initializer.

This is unfortunately necessary for assignment between types imported from C.

* Tiny simplification of the initializer.
2016-07-26 14:21:15 -07:00
Andrew Trick
0ed9ee8dee Revert "Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3724)"
This reverts commit ece0951924.

This results in lldb failues on linux that I can't readily debug.
Backing out until they can be resolved.
2016-07-26 02:50:57 -07:00
Andrew Trick
ece0951924 Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3724)
* Migrate from `UnsafePointer<Void>` to `UnsafeRawPointer`.

As proposed in SE-0107: UnsafeRawPointer.

`void*` imports as `UnsafeMutableRawPointer`.
`const void*` imports as `UnsafeRawPointer`.

Occurrences of `UnsafePointer<Void>` are replaced with UnsafeRawPointer.

* Migrate overlays from UnsafePointer<Void> to UnsafeRawPointer.

This requires explicit memory binding in several places,
particularly in NSData and CoreAudio.

* Fix a bunch of test cases for Void->Raw migration.

* qsort takes IUO values

* Bridge `Unsafe[Mutable]RawPointer as `void [const] *`.

* Parse #dsohandle as UnsafeMutableRawPointer

* Update a bunch of test cases for Void->Raw migration.

* Trivial fix for the SceneKit test case.

* Add an UnsafeRawPointer self initializer.

This is unfortunately necessary for assignment between types imported from C.

* Tiny simplification of the initializer.
2016-07-26 02:18:21 -07:00
Chris Lattner
8e12008d2b Mark tuple splat and ++/-- as errors instead of warnings. This
wraps up SE-0004 and SE-0029.

I consider the diagnostic changes in Constraints/lvalues.swift to be
indicative of a QoI regression, but I'll deal with that separately.
2016-04-16 23:44:22 -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
Max Moiseev
a49dab6bf8 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-29 12:08:52 -08:00
Daniel Duan
780b58a9a5 [Parser] update tests for 'inout' syntax adjustment 2016-02-26 01:33:22 -08:00
Max Moiseev
a7339e67ac Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-22 11:36:07 -08:00
Chris Lattner
82e5c0c592 Update various tests to stop using ++/-- 2015-12-21 18:07:37 -08:00
Dmitri Gribenko
3d0ad16094 Unsafe[Mutable]Pointer.memory => .pointee 2015-12-16 15:50:31 -08:00
Chris Lattner
58fbd1b588 Add some testcases for some radars that are fixed on master. 2015-12-09 16:39:20 -08:00
gregomni
83a5e2cd37 Fix for SR-7
Add check for inout type getting set on DeclRef, diagnose missing
ampersand if so. Also added verifier that DeclRefs are never inout.
Added test.
2015-12-08 08:51:18 -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
Jordan Rose
dbe1230d31 When an assignment fails, check isSettable instead of asking for a setter.
Otherwise, we'll hit an assertion failure (or produce the wrong message)
when a property has an addressor instead of a getter and setter.

rdar://problem/22363304

Swift SVN r31865
2015-09-10 22:33:48 +00:00
Chris Lattner
7ad6eaad07 the previous patch improved 22308291 enough to consider it done.
Swift SVN r31697
2015-09-04 22:35:42 +00:00
Chris Lattner
34ae9bb9b6 Fix <rdar://problem/22584076> QoI: Using array literal init with dictionary produces bogus error
This includes a few changes:
 - Enhance diagnoseGeneralConversionFailure to not ignore constraints that are fully solved by
   CSDiags' heuristics.
 - Enhance dictionary/array literals diagnostics to handle non-compliance to their literal 
   protocols with a specific and custom error message.
 - Add specific QoI for turning accidental use of array literals in dictionary context into
   the right dictionary syntax (with a fixit).


Swift SVN r31696
2015-09-04 22:31:21 +00:00
Chris Lattner
712d3447ce improve some diagnostics around inout expr.
Swift SVN r31415
2015-08-22 22:29:14 +00:00
Chris Lattner
248727780f Now that enough yaks are cleanly shaven, completely reimplement how
we process contextual constraints when producing diagnostic.  Formerly,
we would aggressively drop contextual type information on the floor under
the idea that it would reduce constraints on the system and make it more
likely to be solvable.  However, this also has the downside of introducing
ambiguity into the system, and some expr nodes (notably closures) cannot
usually be solved without that contextual information.

In the new model, expr diagnostics are expected to handle the fact that
contextual information may be present, and bail out without diagnosing an
error if that is the case.  This gets us more information into closures,
allowing more specific return type information, e.g. in the case in
test/expr/closure/closures.swift.

This approach also produces more correct diagnostics in a bunch of other
cases as well, e.g.:

-  var c = [:]  // expected-error {{type '[_ : _]' does not conform to protocol 'DictionaryLiteralConvertible'}} 
+  var c = [:]  // expected-error {{expression type '[_ : _]' is ambiguous without more context}}

and the examples in test/stmt/foreach.swift, test/expr/cast/as_coerce.swift,
test/expr/cast/array_iteration.swift, etc.

That said, this another two steps forward, one back thing.  Because we
don't handle propagating sametype constraints from results of calls to their
arguments, we regress a couple of (admittedly weird) cases.  This is now 
tracked by:
<rdar://problem/22333090> QoI: Propagate contextual information in a call to operands

There is also the one-off narrow case tracked by:
<rdar://problem/22333281> QoI: improve diagnostic when contextual type of closure disagrees with arguments



Swift SVN r31319
2015-08-18 23:55:02 +00:00
Chris Lattner
6c3976061c If a contextual type is available when type checking collection literals, use it to
produce specific diagnostics about individual elements being incorrect instead of
complaining about the whole thing in aggregate.

This improves diagnostics immediately, but is also important to unblock future progress.



Swift SVN r31264
2015-08-17 16:41:55 +00:00
Chris Lattner
b6206ab418 add fixit checks to various type checker testcases
Swift SVN r31004
2015-08-04 20:30:54 +00:00
Chris Lattner
dcfc6180cf improve QoI of inout argument failures, and strip some single element tuple labels.
Swift SVN r30908
2015-08-01 05:20:23 +00:00
Chris Lattner
97e6a50148 Start using contextual information from function calls to diagnose issues in their
argument.  For now we start with some of the most simple cases: single argument 
calls.  This dramatically improves the QoI for error messages in argument lists,
typically turning a error+note combo into a single specific error message.

Some minor improvements coming (and also generalizing this to n-ary calls), but it 
is nice that all the infrastructure is starting to come together...



Swift SVN r30905
2015-08-01 04:37:52 +00:00
Chris Lattner
f2746eaf7b Add inout expr validation to the SyntacticUseRestrictions checker
in MiscDiagnostics, allowing us to correctly and consistently reject 
InOutExprs that do not appear in argument contexts.


Swift SVN r30746
2015-07-29 01:02:46 +00:00
Slava Pestov
6256158eb7 Sema: Fixes for stored let property access from constructor
isSettable() returns true for these, but they don't have a setter.
Tread carefully around them.

Fixes <rdar://problem/21877598> and <rdar://problem/21933630>.

Swift SVN r30631
2015-07-25 19:55:00 +00:00
Chris Lattner
107282297f two changes:
1) Teach resolveImmutableBase about SubscriptExprs that have 
resolved the decl that they are referring to.  This fixes case where we'd
generate an imprecise diagnostic because we weren't able to find the
result in the ResolvedOverloadSet list (which is because CSApply rewrite
it to a different expr node and the locator can't find it).

2) Change FailureDiagnosis::typeCheckIndependentSubExpression to have a
   blacklist of expressions that aren't recursed into, along with rationale
   for each node kind, instead of a short white list.  This produces more
   predictable results, e.g. producing the right diagnostic in 
   ClangModules/objc_parse.swift



Swift SVN r30118
2015-07-11 21:40:18 +00:00
Chris Lattner
55bcdb9099 Reapply the fix for <rdar://problem/21369926> Malformed Swift Enums crash playground service
Completely revamp getTypeOfIndependentSubExpression, to return the subexpression produced by 
type checking instead of just a type. This is important for cases when type checking changes
the root of the AST (e.g. resolving an unresolved_dot_expr) and allows us to eliminate grungy 
and unsafe recovery code that was in place to work around this.  The last point makes the
examples in Constraints/lvalues.swift better (giving a somewhat generic error instead of an 
specific-but-incorrect error that 'z' is immutable), 

but more importantly, it fixes a class of crashers like:
 <rdar://problem/21369926> Malformed Swift Enums crash playground service 
where we'd end up with a LiteralExpr typed as Int instead of a Builtin integer type of some sort.



Swift SVN r30028
2015-07-09 17:32:59 +00:00
Chris Lattner
31facf7204 revert r29932, which is triggering a problem on the ASAN bot that I need to investigate.
Swift SVN r29978
2015-07-08 17:14:43 +00:00