Commit Graph

1092 Commits

Author SHA1 Message Date
Slava Pestov
1975b107f9 Sema: Fix recently-introduced crash with diagnostics of inout parameters
Recently TupleTypeElt was changed to add an inout bit. It is no
longer valid to construct tuple types whose elements have InOutType,
and instead the flag on the element must be set instead.

Update diagnoseImplicitSelfErrors() for the new convention.

Fixes the only remaining crash in the test case from <rdar://19569255>,
but the original issue were fixed long ago.
2017-08-06 00:43:23 -07:00
Slava Pestov
bf2ca1ab94 Sema/AST: Don't crash when stdlib declarations are missing
I don't have reduced test cases. The original test cases
were a series of frontend invocations in -parse-stdlib
mode.

While the original bugs seem to have been fixed, while
verifying I found a few places where we weren't checking
for null decls property in the ASTContext.

Probably not too useful to check this in, but I don't see it
causing any harm, either.
2017-08-06 00:43:23 -07:00
Pavel Yaskevich
80408d6b82 [QoI] Prevent a crash during diagnostics of ternary/if statements
While trying to diagnose problems with ternary/if statements don't
allow clauses, when type-checked separately, to have unresolved type
variables because that doesn't help to find errors.
2017-08-03 12:16:53 -07:00
Pavel Yaskevich
e8744af283 [QoI] Improve diagnostics for assignment expression
Currently `visitAssignExpr` always attempts to use type
derived from destination as a contextual type for assignment
source type-checking, which doesn't always lead to better
results.

Resolves: SR-5081
2017-08-02 18:17:49 -07:00
swift-ci
995a0e77b6 Merge pull request #11281 from xedin/rdar-24329052 2017-08-01 12:56:29 -07:00
Pavel Yaskevich
bfbbcc1c91 [QoI] Improve diagnostics for misaligned archetypes with the same name in calls
Resolves: rdar://problem/24329052.
2017-08-01 12:17:16 -07:00
Alex Hoppen
ebd701c4b7 Represent the name of destructors by a special DeclBaseName
No longer use the known identifier `deinit` for destructors. This allows
classes to have functions called `deinit`.
2017-07-28 19:20:02 +02:00
Slava Pestov
b316dfc676 Sema: Fix constructor diagnostics
Noticed by inspection. I don't have a test case.
2017-07-27 22:04:39 -07:00
swift-ci
18c8dc58ab Merge pull request #11223 from xedin/rdar-33477726 2017-07-27 15:47:11 -07:00
Pavel Yaskevich
242006706e [QoI] Improve diagnostics of unsatisfied generic requirements
Fixes a problem related to presence of InOutType in function parameters
which diagnostics related to generic parameter requirements didn't handle
correctly, and improves diagnostics for unsatisfied generic requirements
in operator applications, which we didn't attempt to diagnose at all.

Resolves: rdar://problem/33477726
2017-07-27 15:06:12 -07:00
John McCall
0730a27f5b Compute the expression range correctly for substring-to-string fixits.
rdar://33474838
2017-07-26 19:10:55 -04:00
Robert Widmann
04e4c8c9ce Update CSDiag to use the proper InOutType convention 2017-07-26 13:15:19 -07:00
David Zarzycki
1504c2ede7 [QoI] Ignore implicit conversions during mutation diagnostics
This change helps diagnoseSubElementFailure() avoid the unknown error
path in more scenarios.
2017-07-21 10:09:47 +01:00
Joe Groff
6e9f4dcd62 Sema: Avoid asking for the SecondType of Constraints that don't have them.
Assertions tripped while trying to reproduce SR-5513.
2017-07-20 16:04:30 -07:00
Robert Widmann
fd7c1f8bc0 Merge pull request #10889 from CodaFi/the-bit-ter-pill
Consistently Pass Parameter Flags
2017-07-19 13:14:50 -07:00
Robert Widmann
2968b03312 Merge pull request #11048 from CodaFi/optional-illusion
[NFC] Adjust return type of getTypeOfExpressionWithoutApplying
2017-07-19 10:45:27 -07:00
Robert Widmann
5dfe3364a2 Redo a hack in CSDiag
Turns out keeping the "mutability classifier" only affects one diagnostic.
2017-07-19 09:49:32 -07:00
Robert Widmann
8cdddef2f8 Refactor Params to use flags
Also, begin to pass around base types instead of raw InOutType types.  Ideally, only Sema needs to deal with them, but this means that a bunch of callers need to unwrap any inouts that might still be lying around before forming these types.

Multiple parts of the compiler were slicing, dicing, or just dropping these flags.  Because I intend to use them for the new function type representation, I need them to be preserved all across the compiler.  As a first pass, this stubs in what will eventually be structural rules as asserts and tracks down all callers of consequence to conform to the new invariants.

This is temporary.
2017-07-19 09:49:32 -07:00
Slava Pestov
707e6de9a4 Merge pull request #10436 from slavapestov/gut-resolve-type-in-context
Remove DeclContext walk from resolveTypeInContext()
2017-07-19 01:10:55 -07:00
Pavel Yaskevich
4d2ace6ff0 Merge pull request #11049 from xedin/rdar-32431736-fix
[QoI] Fix position of the fix-it related to raw representable conversion
2017-07-18 23:12:37 -07:00
Pavel Yaskevich
2bec75e069 [QoI] Fix position of the fix-it related to raw representable conversion
Part of the fix-it for conversion from optional to raw representable
was inserted at the incorrect position which produces invalid expression.

Resolves: rdar://problem/32431736
2017-07-18 22:13:20 -07:00
Slava Pestov
83684eb08a Sema: Remove LookupResult::Entry in favor of AST's LookupResultEntry
Both types store a base declaration and a result declaration;
we can remove one. Soon, it will change to store a base
declaration context, instead.
2017-07-18 22:09:19 -07:00
Robert Widmann
c42f4eabc6 Remove a latent Optional<Type> from independent expr checking 2017-07-18 19:35:28 -07:00
Robert Widmann
ebfb3e8fd5 [NFC] Merge ExprCleaner and ExprCleanser
The distinction was made between these two because of rdar://25341015,
wherein we needed a diagnostic that could detect the shadowing of
global functions by calls in protocols that don't match any
of the protocol's members.

This used to function by hoping that we had an argument tuple type lying
around after type checking.  The expr cleaner would re-write that
type into the AST and we would look up based on it.  Now that we write
Type() into the AST on failure, we must instead type check the
component parts of the argument themselves to form a tuple
type to make the lookup.
2017-07-18 18:15:37 -07:00
Mark Lacey
96ff76cf83 [CS] Use the type map in eraseOpenedExistentials. 2017-07-17 14:18:49 -07:00
Mark Lacey
3d387dd906 Change typeCheckExpression() to Type.
Doing this allows us to return ErrorType in some circumstances where we
want to communicate that we don't have a usable type rather than writing
ErrorType directly into the type of the expression root, avoiding a
mutation of the expression tree in a failure case.
2017-07-16 23:43:13 -07:00
Mark Lacey
9e4523a463 [CS] Use ConstraintSystem::getType. 2017-07-16 12:19:52 -07:00
Mark Lacey
fff29b1bb6 Update CSDiag to hold ConstraintSystems by reference. 2017-07-16 00:18:27 -07:00
Slava Pestov
a39b5eb53b Sema: Move preCheckExpression() out of solveForExpression()
There are two "RAII cleaners" here:

- CleanupIllFormedExpressionRAII cleans up the Expr in its final state
- ExprCleanser walks the Expr before it is mutated and collects
  sub-expressions, then cleans those up after

The subtle difference comes into play if we started to apply the
solution (which can fail, leaving the AST in an inconsistent state)
or if preCheckExpression() modified the AST.

The latter case was causing an ASan failure because we were not
cleaning up type variables in new nodes introduced by
preCheckExpression().

Fix this by moving the preCheckExpression() call out of
solveForExpression(), so that if solveForExpression() is called
with TypeCheckExprFlags::SkipApplyingSolution, we don't mutate the
AST at all.

Sigh...

Fixes <rdar://problem/33277279>.
2017-07-14 16:46:51 -07:00
Alex Hoppen
f8c2692f79 Introduce special decl names
Special DeclNames represent names that do not have an identifier in the
surface language. This implies serializing the information about whether
a name is special together with its identifier (if it is not special)
in both the module file and the swift lookup table.
2017-07-11 19:04:13 +02:00
Mark Lacey
916ce8994b [Constraint system] Update type map code for recursion through salvage().
When we track which expressions we're already in the middle of type
checking, we need to ensure that we also track the constraint system
which has the types for that expression, and then transfer those types
into our current constraint system so that we do not fail to look them up.
2017-07-09 12:11:31 -07:00
Robert Widmann
9a4fb8c2f0 Merge pull request #10790 from CodaFi/disjunction-junction
[Gardening] Rename getInOutOrLValueObjectType to getWithoutSpecifierType
2017-07-06 11:28:21 -07:00
Pavel Yaskevich
be204f27d2 Merge pull request #10779 from xedin/rdar-33135487
[QoI] Don't try to lookup members on incorrect type while diagnosing keypath components
2017-07-06 10:04:42 -07:00
Robert Widmann
957d633185 Rename getInOutOrLValueObjectType to getWithoutSpecifierType
Prepares the AST for a future in which more than just inout and
@lvalue need to be stripped off of ephemeral types.
2017-07-06 09:35:04 -07:00
Alex Hoppen
ff6747de77 Merge pull request #10745 from ahoppen/diagnostics-adjustments-declname
[Diag] Change function diagnostics to take a DeclName parameter
2017-07-06 13:26:56 +02:00
Pavel Yaskevich
c45073efd1 [QoI] Don't try to lookup members on incorrect type while diagnosing keypath components
While trying to diagnose problems related to keypath components
don't assume that type of the component is always correct, check
before trying to see if it's bridged type or has members.

Resolves: rdar://problem/33135487
2017-07-05 17:19:05 -07:00
David Rönnqvist
00833a2343 [QoI] Improve the fix-it for out-of-order arguments.
Change the fix-it to move the argument to its correct location in one go. This happens by removing it from one location and inserting it in the other (as opposed to the original implementation which swapped one argument with the preceding one). The commas separating the arguments are adjusted to match the moved argument.

Add new tests for reordering regular arguments, variadic arguments, and function arguments.

Resolves: SR-4715 rdar://problem/31849281
2017-07-02 10:15:18 +02:00
Alex Hoppen
f35f29d9cf [Diag] Change function diagnostics to take a DeclName parameter
This provides richer error messages that include the function's
parameters
2017-07-01 13:37:08 +02:00
Pavel Yaskevich
a82b16fb2d [QoI] Don't assume that contextual type is always present for trailing closure diagnostics
Fixes crasher in diagnostics related to the fact that contextual type
is not always available when trying to diagnose problems related to
calls with trailing closures.

Resolves: rdar://problem/33067102
2017-06-29 23:09:55 -07:00
practicalswift
d39719ec3f [gardening] Fix typos 2017-06-29 23:09:22 +02:00
Pavel Yaskevich
ef55d42334 [QoI] Emit shadowing diagnostics even if argument types do not much completely
Relax restriction placed on the function shadowing diagnostics
and allow such diagnostics to be emitted even when argument types
do not match expected parameter types, but use "near match" message
in that case to clarify that shadowing is not exact.

Resolves: rdar://problem/32854314
2017-06-28 13:35:26 -07:00
Pavel Yaskevich
1ffac2e651 [QoI] Improve diagnostics related to member calls
When trying to diagnose problems related to calls where
function is represented by a member of nominal type let's
attempt to be more cautious while type-checking function
expression without it's arguments, because it could produce
unrelated diagnostics.

Resolves: rdar://problem/32551313, rdar://problem/28456467, rdar://problem/31671195
2017-06-27 15:49:11 -07:00
swift-ci
f9b2047cc0 Merge pull request #10571 from xedin/sr-5045 2017-06-26 14:08:42 -07:00
Pavel Yaskevich
4e6677e7c4 [QoI] Improve contextual error diagnostics related to calls
Currently some contextual errors are discovered too late
which leads to diagnostics of unrelated problems like argument
mismatches, these changes attempt to improve the situation
and try to diagnose contextual errors related to calls
before everything else.

Resolves: SR-5045, rdar://problem/32934129
2017-06-26 13:12:32 -07:00
Alex Hoppen
949968a182 Adjust printing to take into account special DeclNames
Print DeclBaseNames using a new userFacingStr() method to prepare for
DeclBaseNames that are not backed by Identifiers
2017-06-24 11:39:09 +02:00
Huon Wilson
18078c104e Merge pull request #10476 from huonw/cleanups
Small clean-ups
2017-06-22 14:30:46 -07:00
Huon Wilson
77781b8754 [NFC] Use std::tuple instead of hand-written lexicographical comparison. 2017-06-22 12:48:55 -07:00
Robert Widmann
da35f11486 Merge pull request #10453 from CodaFi/high-and-DRY
Unify CallArgParam and AnyFunctionType::Param
2017-06-21 14:11:26 -07:00
Pavel Yaskevich
676a48ff4f [QoI] Adapt new diagnostics to reverted portion of SE-0110 and new function input decomposition 2017-06-21 12:29:29 -07:00
Robert Widmann
0795c9946c Unify CallArgParam and AnyFunctionType::Param 2017-06-21 11:31:51 -07:00