Commit Graph

282 Commits

Author SHA1 Message Date
Slava Pestov
744850749b Sema: Fix 'for ... in ...' over a sequence of DynamicSelfType 2019-05-15 14:34:10 -07:00
Sam Lazarus
ede8127adf Test: Add and update tests for allowing var and let as argument labels 2019-04-26 04:08:27 -04:00
Slava Pestov
1889d5aa45 Sema: Correctly simplify member types with a DynamicSelfType base
Fixes <https://bugs.swift.org/browse/SR-10434>, <rdar://problem/49779783>.
2019-04-12 01:00:19 -04:00
Slava Pestov
998e62005a Sema: Don't diagnose availability errors twice in non-single-expression closures 2019-04-02 20:37:01 -04:00
Slava Pestov
6bb36b5c01 Sema: Subscript default arguments
Fixes <https://bugs.swift.org/browse/SR-6118>.
2019-04-02 20:37:01 -04:00
Ted Kremenek
fe215edb9b Merge pull request #19743 from Azoy/smarter-struct-init
[Sema] Synthesize default values for memberwise init
2019-03-25 17:31:01 -07:00
John Holdsworth
dbe99d771e Make Self available to member functions (SE-0068?) (#22863)
* Make Self available to instance member functions (SE-0068?)

* Works for value types and static functions.

* Further experiments with TypeExpr

* Move Self processing off diagnostic path

* diagnostic instead of assertion fail

* TypeExpr of DynamicSelfType now working.

* Update tests for availability of Self

* Cast to Self fixed!

* Self not available as type in classes except for return type

* Could it be this simple?

* Nearly there

* Fix function decls using Self inside methods.

* Fix validation-test/compiler_crashers_2_fixed/0164-sr7989.swift

* Fix of ./validation-test/compiler_crashers_2_fixed/0179-rdar44963974.swift

* "Un-fix" validation-test/compiler_crashers_2_fixed/0164-sr7989.swift

* CHANGELOG entry

* Update CHANGELOG.md

Co-Authored-By: johnno1962 <github@johnholdsworth.com>

* Update CHANGELOG.md
2019-03-15 23:23:19 -04:00
Azoy
bc7cb332df Fix generic types
add tests

get parent init
2019-03-14 04:07:24 -05:00
Pavel Yaskevich
9802875ce1 Merge pull request #23187 from theblixguy/fix/SR-10062
[Typechecker] Disallow default argument to inout parameter
2019-03-12 12:11:00 -07:00
Suyash Srijan
e21430a6af [typechecker] disallow default argument to inout parameter 2019-03-12 02:57:28 +00:00
David Zarzycki
31d8153097 [Sema] QoI: Report all tuple type resolution errors
This improves single pass diagnostics when more than one tuple type
element has problems.
2019-03-11 16:03:17 -04:00
Doug Gregor
61caa51e29 Update test case for subscript argument labels 2019-03-01 10:59:30 -08: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
Slava Pestov
feb140129c Sema: Add test for operator returning Self
We didn't have a test for it, as I discovered while adding some assertions.
2019-02-07 23:46:31 -05:00
Pavel Yaskevich
43670cb897 [TypeChecker] Classify nil literal and .none as non-contriburing to throws
Original fix for SR-9102 stripped throws bit from the function types
nested inside optionals before attempting bindings, that doesn't
work with e.g. default parameter values because conversions from
throwing and non-throwing functions are only allowed in subtype
relationship but function types nested inside optionals are going
to be equated.

So this patch takes an alternative approach and attempts to pattern
match `nil` literal and `.none` use and classify argument as
non-contributing to throws.

Resolves: rdar://problem/47550715
2019-01-29 10:27:37 -08:00
Slava Pestov
1b27618e3e Sema: Teach rethrows checking about OtherConstructorDeclRefExpr
Fixes <https://bugs.swift.org/browse/SR-8788>.
2019-01-18 00:35:03 -05:00
Slava Pestov
f34d2024be Sema: Fix crashes when a call of a closure value is missing a 'try'
Two problems here:

- The InterpolatedString instance variable was not always initialized before
  being checked for null

- In the non-null case, we were assuming the result of CallExpr::getCalledValue()
  was non-null, but it's null if the callee is not a function declaration

Fixes <rdar://problem/46973064>.
2019-01-08 21:42:30 -05:00
fischertony
555414a3ac [Tests] Add tests for unary operators on tuples 2018-11-07 01:34:38 +03:00
Slava Pestov
3265bffa8f Parse: Remove the fixit for curried parameter lists, its wrong anyway
Fixes <rdar://problem/45274153>.
2018-10-30 14:02:35 -04:00
Greg Titus
7d0bdb112e Omit protocol match diagnosis for constructors with differing names. 2018-10-14 17:08:50 -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
Mark Lacey
352e4a2de4 [ConstraintSystem] Infer empty closures as returning () more eagerly.
We previously allowed these closures to default to (), but be inferred
as other types as well, which means that we will find some expressions
to be ambiguous because we end up finding multiple viable solutions
where there is really only one reasonable solution.

Fixes: rdar://problem/42337247
2018-09-12 13:30:35 -07: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
Slava Pestov
f0e72290d4 Sema: Fix handling of parentheses around 'inout T'
In Swift, wrapping the type of a function parameter in parentheses
never changes its meaning. By this logic,

  func foo(x: (inout Int))

should be equivalent to

  func foo(x: inout Int)

This worked in Swift 4.1 but regressed when the new function type
representation was introduced.
2018-08-10 18:41:52 -07:00
Slava Pestov
f11b6200b1 AST: Set invalid bit in ValueDecl::setInterfaceType()
The verifier asserts that declarations whose interface type contains an error
are invalid, so let's just mark them invalid when we set the interface type,
instead of needlessly duplicating this logic all over the declaration checker.
2018-08-10 13:33:12 -07:00
Mark Lacey
edfe4ebb54 Add a test for SR-6299.
This was fixed a while ago.
2018-07-26 10:33:31 -07:00
Slava Pestov
c0fc4f4b0d Sema: Add test that self.init delegation cannot refer to a function
This covers <https://bugs.swift.org/browse/SR-8350>, which is
already fixed.
2018-07-24 14:46:28 -07:00
Mark Lacey
8ee52763f0 Remove the '++' and '--' operators.
We still had unavailable versions of these for floating-point types
only. We shouldn't need to keep these around, and can instead just
emit a helpful diagnostic for anyone that attempts to use them.

Unfortunately I don't see any way for the diagnostic to produce an
actual fix-it, so it just suggests '+= 1' or '-= 1' without actually
producing a fix.
2018-07-12 15:46:57 -07:00
Pavel Yaskevich
5c3a913097 Merge pull request #17225 from AnthonyLatsis/range-oper-misspell-fixits
[TypeChecker][Diag] Suggest fixits for close-match range operators
2018-07-03 12:54:06 -07:00
Slava Pestov
3701f745c4 Migrate various Sema tests to Swift 4 2018-06-25 01:02:20 -07:00
Slava Pestov
5d2752f7d2 Run tests with -swift-version 4 by default
Some test now fail, so add an explicit -swift-version 3.
2018-06-19 23:24:19 -07:00
Slava Pestov
75bef7ca20 Sema: Fudge backward compatibility for init special declname
In Swift 4, constructors had the same name as properties,
methods and enum cases named `init`. This meant that you
could use constructor syntax to call such a member, which
caused some confusing behavior.

Recently I added a special declname for `init` so that
constructors have unique names distinct from any name you
can spell, and "foo.init" syntax would look for a member
with the special name rather than one named `init`.

Unfortunately people actually had code where they defined
members named `init` and then use them via normal member
lookup syntax, like this:

enum E {
  case `init`
}

let e: E = E.init

So to maintain backward compatibility, hack member lookup
to also find members named `init` when looking up the special
declname for constructors.

The workaround is only enabled in Swift 4 and 4.2 mode;
in Swift 5 mode you are expected to write "foo.`init`" to access
non-constructor members named `init`.

Fixes <rdar://problem/38682258>.
2018-06-14 20:41:27 -07:00
fischertony
110b2c12b0 [TypeChecker][Diag] Suggest fixits for close-match range operators 2018-06-15 02:36:29 +03:00
Mox Soini
596664f442 Flip static/class in error for using class method in protocol 2018-06-07 23:33:58 +03:00
Hamish Knight
8af821d6fb [Sema] Treat a lazy property's synthesised getter as being a property initialiser for error handling diagnostics
The only code we should be diagnosing on in such a context is within the property's initialiser expression that has been transplanted from the var's pattern binding decl. We don't perform the analysis on the init expr while it's still a part of the original PBD, as it doesn't get a solution applied there.
2018-06-06 17:06:28 +01:00
Hamish Knight
c21d9a4777 [Sema] Don't mark apply exprs as non-throwing if they haven't been type checked yet
Apply exprs in initialiser expressions for lazy properties were being incorrectly marked as not throwing due to the fact that initialiser expressions for lazy properties don't have a solution applied to them until they get type checked as a part of the synthesised getter.
2018-06-06 17:06:28 +01:00
Hamish Knight
18e5cc6e62 Move a test from Parse to decl
We're testing a Sema diagnostic, not a Parse diagnostic.
2018-06-06 13:28:02 +01:00
Mox Soini
965124708a Better error message for 'class func/var' usage in protocols 2018-06-04 08:49:28 +03:00
Mark Lacey
5fce236ba9 [Sema] Fix a crash in rethrows checking.
We were assuming that variadic parameters are at the end, so we didn't
fill in all the types of the tuple elements in the tuple type we were
constructing.
2018-05-30 15:23:27 -07:00
Slava Pestov
58d3c102e2 Sema: Handle capture lists in 'rethrows' checking
Fixes <https://bugs.swift.org/browse/SR-7120> and
<rdar://problem/38142105>.
2018-05-10 14:02:16 -07:00
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
Anthony Latsis
96c0c13a2b [Diagnostics] SR-7445 Improve diagnostics for assignment failures (#16179)
* [Diagnostics] SR-7445 Improve diagnostics for assignment failures

* modified messages for assignments to function calls,
   modified messages for assignments to methods.
   removed comment for resolved radar.

* removed extra line and braces

* added tests for assignment_lhs_is_apply_expression
   eliminated redundant literal check which is always invoked before call
   reverted 'cannot assign to value' for literal assignments in subexpressions

* Complemented assigning to literal tests & reverted to 'cannot asign to value' for methods (was 'cannot assign to member')

* removed extra tabs

* eliminated one more accidental spacing

* Update CSDiag.cpp

* added highlighting, fixed & rechecked tests

* added highlighting for complex expressions involving assigning to literals

Resolves: [SR-7445](https://bugs.swift.org/browse/SR-7445)
2018-04-28 15:49:10 -07:00
David Zarzycki
e57467a563 [AST] NFC: Attr.def clean up (#16031)
1) Formalize "OnAccessor". A hack used to alias this to "OnFunc".
2) New aggregates: OnNominalType, OnGenericType, OnAbstractFunction.
3) Consistent and self-documented (albeit custom) style to ease code review/audits.
4) Removes a few cases of `OnAccessor` based on pull request #16031 feedback.
2018-04-24 21:24:48 -04: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
96901f1983 SE-0193: Public default argument generators cannot reference declarations that are @usableFromInline 2018-04-05 16:56:34 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Slava Pestov
34fd4ae512 AST: Use DeclBaseName::Kind::Constructor
Fixes <rdar://problem/35852727>, <https://bugs.swift.org/browse/SR-1660>,
<https://bugs.swift.org/browse/SR-6557>.
2018-03-16 00:25:56 -07:00
Mark Lacey
4c682d52c8 Support functions that return an IUO Self.
We were only looking through plain Optional TypeReprs in decl
checking.
2018-01-11 23:15:03 -08:00
Doug Gregor
cabdf84179 Suggest @objc for overrides of declarations from/in extensions.
The Swift class model does not support overriding declarations where either
the overridden declaration or the overriding declaration are in an extension.
However, the Objective-C class model does, so marking the declaration as
@objc (when possible) will work around the limitation.

Customize the "cannot override declaration in extension" diagnostic to
suggest adding @objc to the overridden declaration in cases where
@objc is permitted. Fixes SR-6512 / rdar://problem/35787914.
2017-12-13 14:54:32 -08:00
Graydon Hoare
0539cc5836 [Diagnostics] s/may/must/ in 'may not be used on variadic parameters' 2017-09-29 16:09:23 -04:00