Commit Graph

9116 Commits

Author SHA1 Message Date
Robert Widmann
1a1157ded5 Merge pull request #11446 from CodaFi/like-a-bridge-over-troubled-decls
Reject member lookups that require bridging metatypes
2017-08-18 01:28:37 -07:00
Pavel Yaskevich
5e7d9bf155 [Diagnostics] NFC: Extract argument<->parameter matcher from diagnoseSingleCandidateFailures 2017-08-16 13:40:20 -07:00
Pavel Yaskevich
7a1bae85ae [ConstraintSolver] NFC: refactor candidate solver to use constraint system arena
While shrinking we have to allocate containers for the reduced domains
for some of the candidates, it's currently done using permanent arena
of the `ASTContext` allocator. This patch changes candidate solver to
use arena associated with the parent constraint system, which significantly
limits lifetime of domain containers.
2017-08-14 12:44:38 -07:00
Robert Widmann
f479f27420 Turn on circularity checks for ProtocolCompositions
When resolving protocol composition types, using the
old type checker to resolve the type manually instead
of the iterative type checker submits a recursive-but-
satisfiable request to the ITC.  This way we directly
resolve through TypeCheckType and can catch the
circularity before it takes down the compiler.
2017-08-14 03:55:22 -07:00
Robert Widmann
3c1a6ab6d3 Reject member lookups that require bridging metatypes
We can only coerce metatypes covariantly but bridging
always requires an unrelated metatype cast.  When
performing member lookup, especially unqualified member
lookup, disregard static members from bridged types entirely.

See SR-5670 and rdar://problem/33830526
2017-08-13 12:39:33 -07:00
Robert Widmann
ba7ae4aca9 [SR-5671] Emit diagnostic in place of collection downcast in pattern
For switch statements like the following

class Animal {}
class Cat : Animal {}
class Dog : Animal {}

func check(_ arry: [Animal]) {
  switch arry {
  case is [Cat]:
    ()
  case let dogs as [Dog]:
    ()
  default:
    ()
  }
}

Collection downcasts are not implemented.  SILGen support requires
refactoring SILGenPattern to emit the collection downcast, but
would be better solved by a future rewrite.

At least offer a more informative diagnostic than what was there
before.
2017-08-11 15:00:31 -07:00
Robert Widmann
7e40f5c69d Merge pull request #11422 from CodaFi/propageno
[NFC] Refactor CSApply's ExprWalker a bit and propagate closure check…
2017-08-10 22:04:11 -07:00
Pavel Yaskevich
a8e43f0718 Merge pull request #11375 from xedin/rdar-27700622
[ConstraintSolver] Fix computeFavoredTypeForExpr not to impose types …
2017-08-10 16:38:11 -07:00
Mark Lacey
09f0587da8 Merge pull request #11415 from davezarzycki/simplify_performMemberLookup_take2
Simplify performMemberLookup()
2017-08-10 16:37:16 -07:00
Robert Widmann
9e13fcb69f [NFC] Refactor CSApply's ExprWalker a bit and propagate closure checking errors
There is exactly one place where the 'skipClosures' needs to be
honored, and that is when applying the solution.

Also, teach typeCheckClosureBody to propagate failures
outward instead of ignoring them.
2017-08-10 15:29:12 -07:00
Pavel Yaskevich
bbaa232731 [ConstraintSolver] Fix computeFavoredTypeForExpr not to impose types on the merged binary operators
`LinkedExprAnalyzer` is not always precise in collecting types of expressions,
so let's not try to impose anything upon linked operator expressions, which are
"mergable", except actually merging argument/result types together to help
constraint solver.

Resolves: rdar://problem/27700622
2017-08-10 12:31:17 -07:00
Pavel Yaskevich
0b7e436edf Merge pull request #11418 from davezarzycki/quick_sema_perf_fix
[Sema] NFC: Do one cache lookup instead of three
2017-08-10 11:17:16 -07:00
David Zarzycki
5a6a1f565c [Diags] Remove dead code already handled by diagnoseSimpleErrors() 2017-08-09 20:25:30 -04:00
David Zarzycki
78298c8d2a [Sema] Remove vestigial member lookup path
The normal lookup path can handle all constructors just fine.
2017-08-09 20:25:09 -04:00
David Zarzycki
0511edc69f [Sema] NFC: Do one cache lookup instead of three 2017-08-09 17:52:22 -04:00
Slava Pestov
0470a7c757 Merge pull request #11402 from davezarzycki/diag_qoi_checkOwnershipAttr2
[Diags QoI] Avoid premature return in checkOwnershipAttr()
2017-08-09 14:14:33 -07:00
Arnold Schwaighofer
8146104b7e Revert "Simplify performMemberLookup()" 2017-08-09 10:56:38 -07:00
David Zarzycki
f0b1924a19 [Diags QoI] Avoid premature return in checkOwnershipAttr()
This also removes some dead code, where an early assert() ensures that
'strong' is never passed into the function, but then the function later
tries to handle 'strong'.

Finally, use a switch statement for future proofing.
2017-08-09 13:13:36 -04:00
Tony Allevato
d9827accc4 [Sema] inout/ASTNode fixes after rebasing 2017-08-08 22:02:23 -07:00
Tony Allevato
fca78a3634 [Sema] Fix type checking for enums defined in other files 2017-08-08 18:30:22 -07:00
Tony Allevato
fd93e03768 [Sema] Forbid synthesis in an extension
The exception is if the conformance is already redundant (for example,
the implicit synthesis for RawRepresentable enums).
2017-08-08 18:30:22 -07:00
Tony Allevato
a3db968057 Move derivesProtocolConformances from AST to Sema 2017-08-08 18:30:22 -07:00
Tony Allevato
aa93ee52e1 Formatting and other cleanup. 2017-08-08 18:30:22 -07:00
David Zarzycki
8b544de6c4 [Diags] Remove dead code already handled by diagnoseSimpleErrors() 2017-08-08 21:26:55 -04:00
David Zarzycki
823e3e16c0 [Sema] Remove vestigial member lookup path
The normal lookup path can handle all constructors just fine.
2017-08-08 21:26:55 -04:00
Tony Allevato
425de49454 [Sema] Synthesize Eq/Hash for enums with payloads, structs 2017-08-08 18:20:58 -07:00
David Zarzycki
dc51a0ac42 [QoI] Better mutation attribute diagnostics
1) Move the "both" check up and don't prematurely return because there
   may be more errors.
2) Remove fix-it when both attributes exist. We simply don't know which
   attribute the programmer wants to keep.
2017-08-08 13:54:54 -04:00
Rintaro Ishizaki
eb6914ccfc Merge pull request #11346 from rintaro/rip-cfor
Eliminate C-style ForStmt
2017-08-08 07:49:42 -07:00
Slava Pestov
2c61ed5c99 Sema: Fix pre-check expression folding nested types of generic parameters
This allows [Foo.Bar](), [Foo.Bar?]() etc to type check if Bar is
an associated type of a generic parameter Foo.

Fixes <rdar://problem/27631137>.
2017-08-06 20:27:47 -07:00
Slava Pestov
cb3dcbe899 Sema: Fix crash when inferring pattern type with bad conformances
Again, no test case -- this was an old radar with a
-parse-stdlib example, and I'm just making this change
to verify that the original crash was fixed.
2017-08-06 00:43:23 -07:00
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
Slava Pestov
edfaf7f724 Sema: Fix name lookup of nominal types nested inside a class from a protocol 2017-08-06 00:21:49 -07:00
Mark Lacey
0b173decf5 Merge pull request #11338 from rudkx/bail-on-too-complex
Remove -swift-version 3 checks for "expression too complex".
2017-08-04 14:45:35 -07:00
swift-ci
4383062538 Merge pull request #11339 from xedin/fix-skip-solutions-with-cache 2017-08-04 13:32:10 -07:00
Rintaro Ishizaki
61fd649081 [AST] Eliminate ForStmt
RIP
2017-08-04 23:27:22 +09:00
Rintaro Ishizaki
344c860c53 [Sema] Remove C-style for statement diagnostics from Sema 2017-08-04 23:27:22 +09:00
Pavel Yaskevich
d18567a672 [TypeChecker] Return correct type when asked to skip applying solution
When type-checker is asked to skip applying deduced solution to expression,
it still needs to use type information for it to return correct result type.
2017-08-03 21:58:49 -07:00
Mark Lacey
9e7b5b22db Remove -swift-version 3 checks for "expression too complex".
This was initially added to avoid "expression was too complex" in a
case where we were not previously reporting it for -swift-version 3
but should have been. In retrospect this seems misguided since
although we would not like to regress on "too complex" expressions, we
really don't want to silently continue in the cases where we decide an
expression is "too complex", but where we have a solution that we
could use. It's better to fail.
2017-08-03 20:33:07 -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
Slava Pestov
3dc4114513 Sema: Fix crash when resolving bound generic type with unbound parent
Eg, if both Foo and Bar are generic, Foo.Bar<Int> would crash.

This was introduced when I refactored the code a bit to combine
the code path for nominal types and generic typealiases. I was
a little too eager in merging them, because in fact the
substitution-based approach doesn't work when the parent type
is an unbound generic, which can occur in the nominal type case.

Note that we skip validation of generic parameters when the
parent type is an unbound generic. This is because there may
be requirements relating the generic arguments of the parent
type with the generic arguments of the nested type, and unless
all arguments are known, we cannot check these requirements.

For example:

struct Outer<T : Collection> {
  struct Inner<U : Collection> where T.Element == U.Element { }
}

When Sema opens the unbound generic type by creating new type
variables for each generic argument, it will also introduce
constraints corresponding to each generic requirement. Therefore
constraint system will eventually fail if the arguments are
wrong.

Fixes <https://bugs.swift.org/browse/SR-5600>,
<rdar://problem/33655028>.
2017-08-02 22:03:57 -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
Slava Pestov
d65ff34a1e Sema: Fix type mixup with unbound method references
When applying a solution containing an unbound reference to
an instance method of a class, the type of the new expression
did not match the type in the constraint system.

Usually this was papered over because CSApply is sprinkled
with coerceToType() calls, but we would crash when passing
an unbound reference to a generic function, or type(of:).
2017-08-01 21:53:06 -07:00
Slava Pestov
db3c74c2a2 Sema: remove unnecessary special case for dynamic method lookup 2017-08-01 21:22:40 -07:00
swift-ci
9328a43b7e Merge pull request #11286 from CodaFi/a-distinctly-negative-attitude 2017-08-01 14:12:17 -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
Robert Widmann
2823a6960f Properly interpolate negative AP literals
Integer and Floating literals are aware of their negation but
do not store the sign in the text of the value.  Retrieve the
sign bit and properly interpolate the text of the literal value
with it to distinguish negative and positive literals.
2017-08-01 09:48:53 -07:00
swift-ci
17ddc5802f Merge pull request #10965 from ahoppen/deinit-special-name 2017-08-01 07:50:00 -07:00
swift-ci
26a98b4141 Merge pull request #11257 from ffried/case_redundancy_check 2017-07-31 13:46:33 -07:00