Commit Graph

1092 Commits

Author SHA1 Message Date
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
Slava Pestov
c677d149bc Sema: Fix some unused variable warnings 2017-09-01 02:04:21 -07:00
swift-ci
45d971cb2a Merge pull request #11531 from mkchoi212/master 2017-08-29 12:18:03 -07:00
Jordan Rose
5f30eac288 Excise "Accessibility" from the compiler (1/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the names of methods, fields, a few local
variables, and even a swift-ide-test flag. The full list is below.

accessibilityForDiagnostics -> accessLevelForDiagnostics
checkAccessibility -> checkAccess
checkGenericParamAccessibility -> checkGenericParamAccess
checkTypeAccessibility -> checkTypeAccess
checkWitnessAccessibility -> checkWitnessAccessibility
computeAccessibility -> computeAccessLevel
computeDefaultAccessibility -> computeDefaultAccessLevel
fixItAccessibility -> fixItAccess
getAccessibilityString -> getAccessLevelString
getAccessibilityStrictly -> getAccessLevelStrictly
getAccessibilityUID -> getAccessLevelUID
getActualAccessibility -> getActualAccessLevel
getDefaultAccessibility -> getDefaultAccessLevel
getMaxAccessibility -> getMaxAccessLevel
getOverridableAccessibility -> getOverridableAccessLevel
getRawStableAccessibility -> getRawStableAccessLevel
getSetterAccessibility -> getSetterFormalAccess
hasAccessibility -> hasAccess
hasDefaultAccessibility -> hasDefaultAccessLevel
inferAccessibility -> inferAccessLevel
inferDefaultAccessibility -> inferDefaultAccessLevel
inferSetterAccessibility -> inferSetterAccessLevel
overwriteAccessibility -> overwriteAccess
overwriteSetterAccessibility -> overwriteSetterAccess
printAccessibility -> printAccess
requiredAccessibilityForDiagnostics -> requiredAccessForDiagnostics
resolveAccessibility -> resolveAccessControl
setAccessibility -> setAccess
setSetterAccessibility -> setSetterAccess
setDefaultAndMaxAccessibility -> setDefaultAndMaxAccess
validateAccessibility -> validateAccessControl

Accessibility -> AccessLevel
AccessibilityFilter -> AccessFilter
IgnoreAccessibility -> IgnoreAccessControl
NL_IgnoreAccessibility -> NL_IgnoreAccessControl
PrintAccessibility -> PrintAccess
PrintInternalAccessibilityKeyword -> PrintInternalAccessKeyword
SetterAccessibility -> SetterAccessLevel

setterAccessibility -> setterAccess
storedPropertyAccessibility -> storedPropertyAccess

-print-accessibility -> -print-access
2017-08-28 11:11:57 -07:00
Mike JS. Choi
3745d6b896 [Diagnostics] Provide contextual type when diagnosing invalid if-exp
Resolves [SR-910](https://bugs.swift.org/browse/SR-910).
2017-08-27 17:18:47 -05:00
gibachan
46a2ea6e2b Use getSelfInterfaceType()
getDeclaredInterfaceType() is invalid for protocol. getSelfInterfaceType() is good for both concrete types and protocol.
2017-08-27 19:05:10 +09:00
gibachan
8b3d36df1b [Qol]Use complete declaration 2017-08-27 07:36:41 +09:00
Slava Pestov
39d7ee2d46 Sema: Fix diagnostics when 'self' in a convenience init has DynamicSelfType
We don't want to print 'Self' here; the actual concrete type
is more useful.

NFC for now, but becomes important once a subsequent patch gives
'self' a DynamicSelfType in convenience initializers.
2017-08-25 23:51:18 -07:00
Robert Widmann
5458fe15a0 Walk into the closure of a CaptureListExpr
Previously, the failure diagnosis visitor would
default to the generic expr walk which would wind
up type checking the closure body and calling it a day.
Walk into the closure of a capture list expression to
emit better diagnostics.

A regression test for SR-5747 is added.
2017-08-23 01:28:43 -07:00
Pavel Yaskevich
47353c25e2 [ConstraintSolver] Skip performance hacks in presence of unavailable overloads
Limit the scope of the performance hacks which currently exist in the
solver even further by disallowing it to skip generic overlaods or stop
in case when previous solutions involve unavailable overloads, which
otherwise might lead to producing incorrect overall solutions.
2017-08-21 14:55:17 -07:00
Pavel Yaskevich
5e7d9bf155 [Diagnostics] NFC: Extract argument<->parameter matcher from diagnoseSingleCandidateFailures 2017-08-16 13:40:20 -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
Arnold Schwaighofer
8146104b7e Revert "Simplify performMemberLookup()" 2017-08-09 10:56:38 -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