Commit Graph

1005 Commits

Author SHA1 Message Date
Mark Lacey
f3a5a9d595 Merge pull request #18252 from rudkx/add-test-for-rdar32057712
Add test for the long-ago fixed rdar://problem/32057712.
2018-07-26 09:24:52 -07:00
Mark Lacey
fc164731b9 Add test for the long-ago fixed rdar://problem/32057712. 2018-07-26 00:55:27 -07:00
Doug Gregor
9b888533d4 [Serialization] Serialize Objective-C method names for accessors.
Due to some short-circuiting in the serialization logic, we never
added @objc getters/setters to a module’s Objective-C method table.
2018-07-25 16:48:50 -07: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
Rintaro Ishizaki
183a1ae180 Merge pull request #17696 from rintaro/sema-rebindself-target
[Sema] Don't make argument paren target of RebindSelfInConstructorExpr
2018-07-22 17:01:05 -07:00
Pavel Yaskevich
9371aaa49b [TypeChecker/SE-0213] NFC: Add couple of additional test-cases 2018-07-17 12:08:59 -07:00
Doug Gregor
945c09b1cc [Type checker] Improve diagnostics when an optional value is not unwrapped.
When we determine that an optional value needs to be unwrapped to make
an expression type check, use notes to provide several different
Fix-It options (with descriptions) rather than always pushing users
toward '!'. Specifically, the errors + Fix-Its now looks like this:

    error: value of optional type 'X?' must be unwrapped to a value of
        type 'X'
      f(x)
        ^
    note: coalesce using '??' to provide a default when the optional
        value contains 'nil'
      f(x)
        ^
          ?? <#default value#>
    note: force-unwrap using '!' to abort execution if the optional
        value contains 'nil'
      f(x)
         ^
         !

Fixes rdar://problem/42081852.
2018-07-13 11:02:04 -07:00
Brent Royal-Gordon
70f788ed7f Merge pull request #17656 from brentdax/thats-what-a-diagnostics-all-about
[Sema] Improve error for inout on conversion
2018-07-11 16:19:34 -07:00
Brent Royal-Gordon
7545b1945f [Sema] Improve error for inout on conversion
The diagnostic when a user attempts to pass an argument requiring an implicit conversion (e.g. declared as a subclass, type conforming to protocol, etc.) to an inout parameter seems to be confusing for users—see e.g. SR-8155, SR-8148. This change replaces it with a more specific diagnostic which clearly suggests a solution. It also includes a fix-it suggesting the user change the type of the original variable if it’s a local with a simple type signature.
2018-07-10 12:31:36 -07:00
Slava Pestov
1d476edfaf Sema: Also diagnose availability inside keypath index expressions 2018-07-05 23:10:37 -07:00
Slava Pestov
cf9b0d6466 Sema: Fix some keypath diagnostic crashers
We would crash in these cases:

- If all lookup results were subscripts
- If all results were unavailable
2018-07-05 23:01:14 -07:00
Slava Pestov
4531d1c0ba Sema: Check availability of key path components
Fixes <https://bugs.swift.org/browse/SR-7406> / <rdar://problem/39319212>.
2018-07-05 17:44:46 -07:00
Rintaro Ishizaki
e694837fc3 [Sema] Don't make argument paren target of RebindSelfInConstructorExpr
For `use(self.init())`, target of RebindSelfInConstructorExpr should be
call expression instead of paren expression.

rdar://problem/41416911
Possibly: rdar://problem/41593987
2018-07-03 17:12:02 +09:00
Slava Pestov
31ab93b82c Remove Swift 3-specific tests 2018-07-02 21:14:22 -07:00
Joe Groff
01dea286ee Merge pull request #17679 from jckarter/nested-collection-upcast-peephole
Sema: Clear the types of exprs changed by collection upcast peepholes.
2018-07-02 19:05:17 -07:00
Joe Groff
64c1737211 Sema: Clear the types of exprs changed by collection upcast peepholes.
`finish{Array,Dictionary}Expr` currently invoke `cs.cacheExprTypes` after building their semantic exprs, which in a nested collection expression, immediately undoes the type changes done by this peephole, leading to crashes due to inconsistencies in the AST later. rdar://problem/41040820
2018-07-02 15:00:30 -07:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
Mark Lacey
16a0808f2c Revert "[TypeChecker] Fix crash with Objective C keypaths." 2018-06-26 17:18:12 -07:00
Mark Lacey
d9e046dbb8 Merge pull request #17497 from rudkx/rdar40955755
[TypeChecker] Fix crash with Objective C keypaths.
2018-06-26 08:35:16 -07:00
Mark Lacey
846f159a5c Also check for error_type in ObjC keypath validation.
And add a test that exercises this exit path (although it won't crash
a compiler without my fixes because we do end up with ErrorType in
that case, not a nullptr).
2018-06-25 23:15:10 -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
swift-ci
8f23048c85 Merge pull request #17097 from brentdax/noescape-from-the-ast-dump-scrape 2018-06-18 16:59:37 -07:00
Joe Groff
194f1f808b Sema: Force the 'getElements' array of a type-checked ArrayExpr to contain rvalues.
There are other parts of CSApply that attempt to peephole transform ArrayExprs (particularly bridging, which tries to turn `[x, y, ...] as T` into `[x as T, y as T, ...]`) and expect the elements to have already been rvalue-d. Fixes rdar://problem/40859007.
2018-06-14 12:08:44 -07:00
Matt Diephouse
456f69e01f Add root type constraint between KeyPath expressions and applications 2018-06-13 12:38:46 -04:00
Pavel Yaskevich
6e9d5f533e Merge pull request #17078 from xedin/rdar-40945329
[Sema] Diagnose misplaced InOutExpr in `preCheckExpression`
2018-06-12 11:13:24 -07:00
Joe Groff
711984234d Sema: Pass the useDC down to getTypeOfReference.
This fixes a subtle issue where, during single-expression closure type inference, we would ask for the settability of local variables from the outer function's context, leading us to mistakenly consider them mutable inside single-expression closure contexts. DI would catch some but not all violations of the expected semantics here.
2018-06-11 10:53:00 -07:00
Brent Royal-Gordon
fb79b8f44e Indicate which closures are escaping in AST dumps 2018-06-10 14:03:01 -07:00
Pavel Yaskevich
3149e2de87 [Sema] Diagnose misplaced InOutExpr in preCheckExpression
It's much easier to diagnose structural problems related to
use of InOutExpr when AST is formed.
2018-06-08 22:53:17 -07:00
Lily Vulcano
63348bce6f Merge pull request #16736 from millenomi/LinuxAsBridging_2
Turn on 'as' bridging for Linux (2)
2018-05-31 09:23:45 -07:00
Lily Vulcano
1377ab7d7e Turn on ‘as’ bridging on Darwin. 2018-05-30 15:07:22 -07:00
Slava Pestov
69701b1b90 AST: Fix "statically derived metatype" check
A static reference to DynamicSelfType can only be written as an
implicit member expression where the contextual type is a
DynamicSelfType, ie, 'return .init(...)' in a static method
returning Self.

In this case, the base expression is not a statically-derived
metatype.
2018-05-29 22:51:25 -07:00
Slava Pestov
ccc23c988b Sema: Fix bug in 'invalid dynamic constructor reference' check
If the base value was 'self', we were allowing a reference to a
non-required initializer, because you're allowed to do this inside
another initializer.

But if you're in a static method, 'self.init' should obey the same
restrictions as 'foo.init' for any other metatype value 'foo'.
2018-05-29 22:51:25 -07:00
Mark Rowe
62eb12b652 Include source ranges for decls in the AST dump. 2018-05-17 10:50:19 -07:00
Ben Langmuir
f20586b3d8 Revert "Include source ranges for statements, declarations, and parameter lists in the AST dump" 2018-05-17 09:53:05 -07:00
Mark Rowe
28af6959b8 Include source ranges for decls in the AST dump. 2018-05-09 11:15:35 -07:00
Mark Lacey
b400b44a15 Merge pull request #16452 from rudkx/rdar39802797
Allowing forming WritableKeyPath to read-only value in Swift 3/4.
2018-05-08 21:40:12 -07:00
Robert Widmann
6ed7e4af59 Merge pull request #16088 from orakaro/exp
More detail diagnostic when downcast to CoreFoundation Type
2018-05-08 21:46:06 -04:00
Mark Lacey
83ebd71644 Allowing forming WritableKeyPath to read-only value in Swift 3/4.
We inadvertantly allowed this in the past, so continue to do so when
compiling in Swift 3/4 mode to avoid suddenly breaking existing code.

The diagnostic here is pretty bad, and I've opened issues for that as
well as providing some kind of deprecation warning for this so that
even under Swift 3/4 mode we alert users that this is unsupported.

rdar://problem/39802797
2018-05-08 14:26:02 -07:00
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
Anthony Latsis
4099e85da6 [Diagnostics & Tests] SR-6052 Prevent nil capitalization (#16256)
And provide better semantic background by surrounding 'nil' in ticks when it is referred to as a value

Added missing tests for certain cases involving nil capitalization
2018-05-03 09:10:30 -07: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
Orakaro
05b78bd984 Reword Note message and use variable name instead 2018-04-27 02:48:44 +09:00
Orakaro
cf68bfb3dd Separate suggestion into different NOTE 2018-04-25 22:07:44 +09:00
fischertony
ba1bbd028d updated missed tests 2018-04-22 20:48:24 +03:00
Orakaro
89452b109c Fix corresponding tests 2018-04-22 00:01:12 +09:00
fischertony
2d375078a3 tests updated for expression_unused_result_unknown diagnostic new text 2018-04-21 02:46:19 +03:00
Doug Gregor
3b896e0a41 [Collection upcast optimization] Address review feedback.
All NFC cleanups.
2018-04-18 09:26:52 -07:00
Doug Gregor
eaba3b3192 [Type checker] Factor out the collection upcast peephole code.
While here, cope with extra parentheses as well. They shouldn't
inhibit this optimization.
2018-04-17 15:21:48 -07:00
Doug Gregor
10c53f4cd8 [Type checker] Extend the upcast-of-literal peephole to dictionary literals.
When the operand of a collection upcast is a dictionary literal,
upcast the elements of the collection instead. This avoids going
through the dynamic-casting machinery.
2018-04-17 14:50:46 -07:00