Commit Graph

1357 Commits

Author SHA1 Message Date
Sho Ikeda
26d650292f [gardening] Use empty() over size() == 0 2018-03-05 14:43:13 +09:00
Pavel Yaskevich
b7e322d877 [Diagnostics] Fix crash in diagnoseSubscriptErrors
If there is a single candidate with a valid index type, don't assume
that such candidate always has a valid function type. There are
multiple examples of this crash we've seen but there is no reproducer
test-case unfortunately.

Resolves: rdar://problem/37565861
2018-02-19 13:49:00 -08:00
Chris Lattner
a0fa5d11b4 Implement SE-0195, which introduces "Dynamic Member Lookup" Types (#14546)
* Implement the recently accepted SE-0195 proposal, which introduces "Dynamic
Member Lookup" Types.  This is a dusted off and updated version of PR13361,
which switches from DynamicMemberLookupProtocol to @dynamicMemberLookup as
was requested by the final review decision.  This also rebases it,
updates it for other changes in the compiler, fixes a bunch of bugs, and adds support for keypaths.  

Thank you to @rudx and @DougGregor in particular for the helpful review comments and test cases!
2018-02-16 16:19:50 -08:00
Pavel Yaskevich
8c17b925e6 [ConstraintSystem] Add TypeLoc caching to constraint system
This is useful for explicit casts and type expressions, where
type loc and expression types might be different, and allows
constraint solver to avoid setting opened types to expressions
which resolves multiple crashes.
2018-02-13 00:08:56 -08:00
Pavel Yaskevich
c0f5711ee5 [ConstraintSystem] Don't apply types to expressions until solution is found
Resolves: rdar://problem/36744895
2018-02-13 00:08:45 -08:00
Mark Lacey
be8defb29e Rename lookThroughAllAnyOptionalTypes to lookThroughAllOptionalTypes. 2018-02-05 23:59:01 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Mark Lacey
3654dcc8fe Remove getImplicitlyUnwrappedOptionalObjectType. 2018-02-03 10:57:11 -08:00
Mark Lacey
3f9689e477 Remove lookThroughImplicitlyUnwrappedOptionalType. 2018-02-03 10:57:10 -08:00
Timur Islamgulov
56d1d6bbd3 Sema: Add a fix-it for integer literal to option set conversion. (#13899)
If expression type is IntegerLiteralExpr and value is equal to '0',
suggest '[]' as a replacement.

Resolves: rdar://problem/20704317 / SR-6716.
2018-01-12 13:34:49 -08:00
Pavel Yaskevich
ce847cc74b Merge pull request #13272 from chuganzy/SR-6272
[DiagnosticsQoI] SR-6272 Tailored diagnostics with fixits for numerical conversions
2018-01-12 01:06:18 -08:00
Mark Lacey
ad1dbac694 IUO: Create disjunctions for optional choices.
When binding an optional value, or function that returns an optional
value, if that value was produced from a decl that was declared an
IUO, create a disjunction.

After solving, make use of the disjunction choices in rewriting
expressions to force optionals where needed.

This is disabled for now, as it results in a source compatibility
issue without associated changes that actually start generating
Optional<T> in place of ImplicitlyUnwrappedOptional<T>. It's
complicated, but basically having two '??' (one returning T, one
returning T?) and creating a disjunction where the first (favored)
choice is ImplicitlyUnwrappedOptional<T> and second is T results in
our selecting the wrong '??' in some cases.
2018-01-08 14:31:03 -08:00
Slava Pestov
d843b10bcc Sema: Fix crash with unresolved dot expression with optional protocol metatype base
Mostly fixes <rdar://problem/35945827>, but there is a case that should
work that does not type check. At least we don't crash though.
2018-01-05 20:33:12 -08:00
Mark Lacey
41479f6334 IUO: Start creating the DeclForImplicitlyUnwrappedOptional OverloadChoice.
Use this in places where we have a decl that is marked with the
ImplicitlyUnwrappedOptionalAttr so that we can distinguish in the
solver which decls need to be potentially unwrapped in order to type
check successfully.
2018-01-04 14:00:36 -08:00
Mark Lacey
d1bb36425d IUO: Add overload choice kind for IUO decls.
Add a new OverloadChoiceKind for decls that are either IUO-typed, or
function-typed meaning that the function result type is IUO-typed.

Not currently used, so NFC.
2018-01-03 19:37:06 -08:00
Takeru Chuganji
0df987a4ff SR-6272 Add fix-it if there is only one candidate 2018-01-03 13:26:36 -08:00
David Zarzycki
62795501d9 [AST] NFC: De-boilerplate "has ParenType sugar" 2017-12-29 11:37:20 -05:00
Takeru Chuganji
5c37ccfc69 SR-6272 Skip if both lhs and rhs are different 2017-12-18 11:26:29 +09:00
Takeru Chuganji
c80b569c2f SR-6272 Use calleeInfo instead 2017-12-17 22:06:20 +09:00
Takeru Chuganji
72cf1585a0 SR-6272: Use contextual type if available 2017-12-16 15:58:57 +09: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
Mark Lacey
d8f492e5d7 Squelch some warnings.
Fix up some dead code warnings as well as a warning for testing
whether an unsigned number is non-negative (which it always is).
2017-12-10 15:21:19 -08:00
Takeru Chuganji
a9db3f2f53 SR-6272: Show “Fix it” for numerical conversions 2017-12-05 00:44:54 -08:00
Jordan Rose
8f8f00012a Merge pull request #12834 from jrose-apple/restrict-cross-module-struct-initializers-2
Implementation of SE-0189 "Restrict cross-module struct initializers to be delegating"

rdar://problem/34777878
2017-11-30 13:32:45 -08:00
Slava Pestov
e360da57bb Sema: Use the correct source range when emitting fixits for unresolved member expressions
Fixes <rdar://problem/34421732>.
2017-11-29 18:23:17 -08:00
Pavel Yaskevich
f5d9c2eb79 [Diagnostics] Fix crash related to diagnostics of trailing closures
While trying to diagnose a problem related to contextual result type
of the trailing closure, don't assume that declaration context is properly
set, instead directly set it to correct one before running type-check.

Resolves: rdar://problem/35699666
2017-11-28 13:12:25 -08:00
Chris Lattner
3f5790fb37 Enhance MemberLookupResult's UnviableCandidates list, NFC.
We now store an entire OverloadChoice in the unviable candidates
list (which is used for error recovery), just like we store them
for viable candidates.

The additional information isn't used, so NFC.
2017-11-26 14:29:00 -08:00
Doug Gregor
e3a5318b97 [Type checker] Teach conformsToProtocol() to check conditional requirements.
conformsToProtocol() is the main way in which we check whether a given type
conforms to a given protocol. Extend it to check conditional requirements by
default, so that an unmodified caller will get the "does not conform" result
(with diagnostics when a location is present) rather than simply ignoring
the conditional requirements.

Some callers take responsibility for conditional requirements, e.g., to
push them into the constraint system. Allow those callers to opt out of
this checking, and do so wherever appropriate.

Fixes rdar://problem/35518088, where we were ignoring the conditional
requirements needed to verify that Equatable synthesis could be performed.
2017-11-21 21:02:00 -08:00
Doug Gregor
1ee30a3132 [Type checker diags] Check generic arguments for any generic function.
This includes functions without type parameters that are generic
because they are members of a generic context. This addresses a
diagnostics regression because the '==' operators for Optional, Array,
and Dictionary were made into members.

The resulting error message is a little ugly, but is more informative
(and much shorter) than what we had before.
2017-11-17 11:01:39 -08:00
Pavel Yaskevich
7b121de1a0 [CSRanking] Change ranking to weight overload choices in evaluation order
Consider different overload choices for the same location in evaluation
order, this makes overload resolution more predictable because it's going
to follow expression bottom-up, that prevents situations when some
expressions are considered ambigious because choices taken further up
equate the score, instead each level is given distinct weight
based on evaluation order.

Resolves: rdar://problem/31888810
2017-11-16 13:38:24 -08:00
Greg Parker
e8475cc130 Revert "Use conditional conformances to implement Equatable for Optional, Array and Dictionary" 2017-11-15 14:17:22 -08:00
Doug Gregor
1f9b28a117 [Type checker diags] Check generic arguments for any generic function.
This includes functions without type parameters that are generic
because they are members of a generic context. This addresses a
diagnostics regression because the '==' operators for Optional, Array,
and Dictionary were made into members.

The resulting error message is a little ugly, but is more informative
(and much shorter) than what we had before.
2017-11-14 16:23:20 -08:00
Jordan Rose
ca1979c920 Improve diagnostics for setting a 'let' property in a delegating init 2017-11-09 18:08:01 -08:00
Slava Pestov
50fa92c8a7 Merge pull request #12567 from gregomni/diagnosis
[Sema] Better ambiguity diagnosis in overloaded function calls
2017-10-22 22:49:39 -07:00
gregomni
345c4a933d Save unresolved arg number from callee candidate info, use it to diagnose ambiguity sooner and
more specifically.
2017-10-22 10:32:11 -07:00
gregomni
18a113e584 We can produce better diagnostics for subscript candidates by noticing when the
subscript is on the destination side of an assignment and restricting matching
overload candidates to only the set-able members.

Also, if we are left with a single candidate, we can recheck unresolved index
expressions with better parameter info.
2017-10-21 14:02:58 -07:00
Greg Titus
bec95b2caa Merge pull request #12368 from gregomni/callee
[Sema] Some cleanup of CSDiag by splitting off the CalleeCandidateInfo class
2017-10-12 13:24:33 -07:00
gregomni
774dbdfa87 Some cleanup of CSDiag by splitting off the CalleeCandidateInfo class and
declaring a few formerly static methods that both files now need in a new
CSDiag.h.
2017-10-11 13:03:48 -07:00
Huon Wilson
ec6c83aa44 [Sema] Check conditional conformances for generic function calls early.
This allows for better (although not perfect) diagnostics, and more guarantees
of correctness.
2017-10-10 20:17:42 -07:00
Slava Pestov
6111a6a964 Sema: Replace a few mapTypeOutOfContext() calls with ArchetypeType::getInterfaceType() 2017-10-07 05:44:58 -07:00
Slava Pestov
6def545696 AST: Remove GenericEnvironment::containsPrimaryArchetype()
This is no longer necessary now that archetypes refer back to a
GenericEnvironment.
2017-10-07 04:46:37 -07:00
Slava Pestov
044af751f3 Sema: Fix a failure to emit a diagnostic
CSDiag was misinterpreting the result of checkGenericArguments().

A result of SubstitutionFailure does not mean a diagnostic was
emitted, only a result of Failure means that. This fixes a case
where we did not emit a diagnostic, result in a crash on invalid.

The diagnostic is still poor, but that's better than crashing.

Fixes <https://bugs.swift.org/browse/SR-5932>,
<rdar://problem/34522739>.
2017-09-27 16:39:06 -07:00
Pavel Yaskevich
9d9a6c6231 [Diagnostics] Restore inout ParamDecl types properly after type-check
We are currently in process of removing `InOutType`
so `VarDecl::get{Interface}Type` is going to wrap base
type into `InOutType` if its flag indicates that it's
an `inout` parameter declaration. But such type can't
be restored directly using `VarDecl::set{Interface}Type`
caller needs additional logic to extract base type.

Resolves: rdar://problem/33613329
2017-09-25 17:38:28 -07:00
Slava Pestov
55916fa128 Sema: Remove usages of getDeclaredTypeOfContext() 2017-09-19 22:12:29 -07:00
Kacper Harasim
3902688b04 [Diagnostics] Resolves: SR-5324 Improved diagnostic when instance member of outer type is referenced from nested type (#11609)
* [Diagnostics] Improved error diagnostics when inner type references instance member of outer type

Resolves: SR-5324.
2017-09-19 14:08:16 -07:00
Slava Pestov
a102341c9c Merge pull request #11640 from gibachan/fixit-nested-static-value
[Qol]Fixit nested static value
2017-09-14 22:56:19 -07:00
Slava Pestov
defb9cd5b6 AST: Add ASTContext::Id_ArrayLiteralElement 2017-09-11 21:48:01 -07:00
John McCall
2d3d6addc0 Delay the validaton of storage accessors until finalization.
The base mutability of storage is part of the signature, so be sure
to compute that during validation.  Also, serialize it as part of
the storage declaration, and fix some places that synthesize
declarations to set it correctly.
2017-09-10 04:56:02 -04:00
Robert Widmann
abce63a1b3 [NFC] Scale back more uses of InOutType 2017-09-05 21:56:58 -04:00
Mark Lacey
49351d11b4 [Constraint system] Emit a debug message when we enter salvage. 2017-09-01 14:00:06 -07:00