Commit Graph

805 Commits

Author SHA1 Message Date
Doug Gregor
2b2e143f59 [Request-Evaluator] Introduce a request for getting an "inherited type". 2018-06-14 15:29:57 -07:00
Doug Gregor
99e540f588 [Evaluator] Add an “enum raw type” request and use it consistently.
Similar to get “superclass of class” request, introduce an “enum raw type”
request that is accessed via EnumDecl::getRawType().
2018-06-14 15:29:57 -07:00
Doug Gregor
ef337bb8ba [Evaluator] Use the request-evaluator for the superclass of a class.
Wire up the request-evaluator with an instance in ASTContext, and
introduce two request kinds: one to retrieve the superclass of a class
declaration, and one to compute the type of an entry in the
inheritance clause.

Teach ClassDecl::getSuperclass() to go through the request-evaluator,
centralizing the logic to compute and extract the superclass
type.

Fixes the crasher from rdar://problem/26498438.
2018-06-14 15:28:36 -07:00
Brent Royal-Gordon
9ede961daa Correct run line on fixed crasher
Lesson learned: the script is not infallible.
2018-06-14 02:05:28 -07:00
Brent Royal-Gordon
27dfa51be5 Wrap interpolated tuples in parens
Keeps them from being interpreted as parameter lists. Fixes SR-7958.
2018-06-13 22:55:48 -07:00
Robert Widmann
dfe42d2e55 Revert "Reject bad string interpolations (#17074)"
This reverts commit fc23f3404d.
2018-06-13 15:06:33 -07:00
Brent Royal-Gordon
fc23f3404d Reject bad string interpolations (#17074)
* Reject bad string interpolations

String interpolations with multiple comma-separate expressions or argument labels were being incorrectly accepted.

* Tweak error name to match message

* Diagnose empty interpolations more clearly

* Don’t double-diagnose parse errors

Fixes a test at Parse/recovery.swift:799 which the previous commit broke.

* Fix incorrect test RUN: line

A previous version of this test used FileCheck instead of -verify, and the run line wasn’t properly corrected to use -verify.

* Update comment

* Add more argument label tests

Ensures that we don’t get different results from an initializer that doesn’t exist or doesn’t take a String.

* Resolve the SR-7958 crasher test

We now diagnose the error and remove the label before it has an opportunity to crash.
2018-06-12 18:46:52 -07:00
Huon Wilson
ec1ed4ca57 Merge pull request #16893 from huonw/errors-are-unresolved-equivalence-class
[GSB] Error types end up as unresolved equivalence classes.
2018-06-04 16:27:48 -07:00
Huon Wilson
10c3e6cea9 [GSB] Error types end up as unresolved equivalence classes.
We need to make sure they don't end up as "concrete" equivalence
classes, because they behave more like unresolved ones.

Fixes rdar://problem/40009245.
2018-05-29 16:21:31 -07:00
Pavel Yaskevich
11ba7e0f42 [CSSimplify] When trying to simplify bind with error type fail gracefully
Since member lookup doesn't check requirements
it might sometimes return types which are not
visible in the current context e.g. typealias
defined in constrained extension, substitution
of which might produce error type for base, so
assignement should thead lightly and just fail
if it encounters such types.

Resolves: rdar://problem/39931339
Resolves: SR-5013
2018-05-28 00:24:54 -07:00
Pavel Yaskevich
3daecc9c4f [TypeChecker] Add test-case for rdar://problem/40165062 2018-05-17 01:49:20 -07:00
Slava Pestov
d466ddfe6e %target-typecheck-verify-swift already expands to the file name 2018-04-30 18:57:17 -06:00
Huon Wilson
69d41e7184 [test] Add test for rdar://problem/37730691. 2018-04-30 12:16:27 +10:00
Huon Wilson
d23bd75358 Merge pull request #16172 from huonw/protocol-typealias-crash
[Sema] Ensure that NameAliasTypes record the right substitutions.
2018-04-27 13:05:15 +10:00
Huon Wilson
be5a3abcd6 [Sema] Ensure that NameAliasTypes record the right substitutions.
If a typealias is inside a protocol, and things are defined in a certain order,
the NameAliasType for that typealias can be constructed before the parent
protocol has been validated (i.e. before its generic environment exists), in
which case it is missing the necessary substitutions.

Fixes rdar://problem/39636312.
2018-04-26 23:55:54 +10:00
Karoy Lorentey
1e1f6b8d92 [stdlib] Remove obsolete hashing interfaces 2018-04-24 17:55:35 +01:00
Doug Gregor
7177b23f93 Merge pull request #16069 from DougGregor/sr-7364
[Conformance checking] Diagnose missing witnesses along "lazy" paths.
2018-04-20 13:27:38 -07:00
Doug Gregor
8146d25641 [Conformance checking] Diagnose missing witnesses along "lazy" paths.
When lazily resolving witnesses, we would fail to diagnose missing
witnesses for which we had no specific diagnostic to give, leading to
AST verifier errors and crashes later on. Make sure we call the
operation to diagnose missing witnesses along these paths, too.

Fixes SR-7364 / rdar://problem/39239629 as well as the older
rdar://problem/36278079.
2018-04-20 11:17:21 -07:00
Doug Gregor
8d2ca387ef The test case from rdar://problem/31164540 is also fixed. 2018-04-20 11:15:22 -07:00
Doug Gregor
bb04d87cd8 [AST] Make TypeBase::adjustSuperclassMemberDeclType() more robust.
When performing substitutions in this function, allow them to fail
more gracefully by producing error types. Fixes SR-7457 /
rdar://problem/39492060.
2018-04-20 11:14:50 -07:00
Pavel Yaskevich
e1fab0559c [Serialization] Always serialize requirement substitutions
Absence of synthetic generic environment should not affect
serialization of the required substitutions because they can
come from outer requirement context for static members.

Resolves: rdar://problem/36497404
2018-04-19 17:58:13 -07:00
Huon Wilson
db8b98bbc9 Merge pull request #15842 from huonw/generic-class-objc-protocol-extension
[Sema] Explicit error for "extension GenericClass : ObjcProtocol".
2018-04-13 09:11:38 +10:00
Huon Wilson
d33a5c16f2 [Sema] Explicit error for "extension GenericClass : ObjcProtocol".
If there was any requirements in the @objc protocol, the user got an error in
some form (a complaint about those requirements), but giving the direct error is
better, and handles @objc protocol with no requirements.

Also, fix a hole in that existing @objc method check: in `class Outer<T> { class
Inner {} }`, Inner should be considered generic, but the loop that was checking
for this didn't consider it.

Fixes https://bugs.swift.org/browse/SR-7370 and rdar://problem/39239512.
2018-04-13 08:09:02 +10:00
Huon Wilson
7c435adc94 [GSB] withoutRedundantSubpath should leave Concrete RequirementSource as Concrete.
Fixes rdar://problem/39316039 and https://bugs.swift.org/browse/SR-7397.
2018-04-12 17:09:10 +10:00
Pavel Yaskevich
3ba6ad654b [TypeChecker] Fix lookup of the dependent type through typealias
While trying to resolve nested type component with type parameter
as a parent, try to resolve it as dependent member directly but
if that fails go through longer resolution path which is required
in case member type is accessed using `typealias`.

Resolves: rdar://problem/39253925
2018-04-09 16:01:37 -07:00
Pavel Yaskevich
7f314d1a2f [TypeChecker] NFC: add test-case for rdar://problem/39040593 2018-04-05 14:15:24 -07:00
Nathan Hawes
d367dfc3ff Merge pull request #15627 from nathawes/reachable-unreachables
[CSGen] Mark visitDynamicMemberRefExpr as unreachable to match ExprRewriter and update SanitizeExpr to handle them
2018-04-02 12:32:44 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Nathan Hawes
0145439a2b [CSGen] Mark visitDynamicMemberRefExpr as unreachable to match ExprRewriter and update SanitizeExpr to handle them
We were hitting an unreachable in visitDynamicMemberExpr in ExprRewriter when
re-typechecking during a salvage. Check for these earlier (in CSGen) and update
SanitizeExpr to handle them.

Resolves rdar://problem/39055736
2018-03-30 17:17:21 -07:00
Pavel Yaskevich
48e71f7325 Merge pull request #15559 from xedin/rdar-38144674
[Sema] Fix `PreCheckExpression` to avoid walking into capture lists
2018-03-28 00:01:35 -07:00
Pavel Yaskevich
e8cd3f94ee [Sema] Fix PreCheckExpression to avoid walking into capture lists
`PreCheckExpression` should only walk into associated closure if
it's a single statement, and should avoid list itself since it should
already be properly type-checked by `typeCheckDecl`.

Resolves: rdar://problem/34852808
2018-03-27 17:18:20 -07:00
Doug Gregor
7e01e54329 [AST] Remove a bogus assertion from the NameAliasType creation function.
Fixes SR-7282.
2018-03-27 09:41:02 -07:00
Pavel Yaskevich
134f4e5611 [Diagnostics] Fix a crash when using withoutActuallyEscaping incorrectly
Teach `eraseOpenedExistentials` how to handle `OpaqueValueExpr`
associated with `MakeTemporarilyEscapableExpr`.

Resolves: rdar://problem/35773761
2018-03-23 14:41:30 -07:00
Pavel Yaskevich
9f7d91323b [Sema] Don't allow member type lookup on existential types
Existential types don't support nested types so let's not
allow the lookup to make such access, with only exception
for typealias or associated types without type parameters,
they are currently allowed.

Resolves: rdar://problem/38505436
2018-03-16 13:53:09 -07:00
Pavel Yaskevich
cdf6cb3f2c [CSApply] Don't try to force propagate l-value access in "shallow" mode
Some of the expressions call into `typeCheckExpressionShallow` while trying to
apply solutions, we need to respect the fact that sub-expressions might be
already properly type-checked while propagating l-value access kind.

Resolves: rdar://problem/38309176
2018-03-15 18:07:51 -07:00
Doug Gregor
823d2a990b [GSB] Always ensure that we wire up typealiases in protocol extensions.
During "expansion" of the requirements of a protocol, we check all of
the inherited associated types against definitions within the
protocol. Also look for concrete types within extensions of that
protocol, so we can identify more places where developers have used
typealiases in inheriting protocols to effect a same-type constraint
on an inherited associated type.

Fixes SR-7097 / rdar://problem/38001269.
2018-03-05 17:10:39 -08:00
Doug Gregor
46e623a089 [SubstitutionMap] Handle conformance lookup via superclass requirements.
Conformances that discoverably for a type parameter via a superclass
requirement occupy a bit of a gray area in the type checker and
generic signature handling right now: we have a type parameter (so the
paths that handle concrete conformances don't kick in), but the
conformance itself isn't modeled as a requirement because it is
available via lookup. Teach SubstitutionMap's conformance lookup to
detect this case and perform conformance lookup in the generic
signature (i.e., falling back to global lookup) in this case,
replicating the hack that IRGen uses to address the same issue when
accessing the conformance (see GenArchetype.cpp's TODO where we lookup
a conformance on the superclass). The removal of that hack (as well as
this one) are tracked by rdar://problem/34609744.

For now, fixes SR-7072 / rdar://problem/37904576.
2018-02-26 23:31:46 -08:00
Pavel Yaskevich
ea0427e9f9 [TypeChecker] Fix crash related to chained optionals in case statements
Type checker didn't handle the safe of disjoint optional chaining when trying
to convert such chaining into `.Some` cases, which leads to dangling
`BindOptionalExpr` in the AST.

Resolves: rdar://problem/35870863
2018-02-22 19:33:48 -08:00
Doug Gregor
8b04dd3dbe [GSB] Avoid unresolved dependent member types in generic signatures.
The GenericSignatureBuilder is allowing unresolved dependent member
types to creep into generic signatures, which eventually blows up in
name mangling. Prefer to pick dependent member types that are
fully-resolved when choosing anchors.

This is a spot fix; a better approach would eliminate the notion of
unresolved dependent member types entirely from
PotentialArchetype. That's tracked by rdar://problem/35839277.

Fixes rdar://problem/36549499.
2018-02-13 15:40:53 -08:00
Pavel Yaskevich
38e305cfdc [DeclChecker] Don't try to derive conformances for invalid enums
If one of the cases is invalid, let's mark parent enum as invalid
as well, and avoid trying to derive any conformances related to it.

Resolves: rdar://problem/36989792
2018-02-05 14:12:55 -08:00
Doug Gregor
e0c39396cc Merge pull request #14154 from DougGregor/sr-6746-test-case
Add now-fixed test case for SR-6746 / rdar://problem/36483751.
2018-01-25 09:37:18 -08:00
Pavel Yaskevich
261ffe4d5c Merge pull request #14100 from xedin/rdar-36449760
[ConstraintSystem] Bind Self to correct contextual type for nested types in protocol
2018-01-25 00:57:41 -08:00
Doug Gregor
3806d56fb7 Add now-fixed test case for SR-6746 / rdar://problem/36483751. 2018-01-24 23:46:57 -08:00
Doug Gregor
597c955948 [Associated type inference] Find tentative type witnesses across protocol hierarchy.
As a minor step toward more global associated type inference,
allow tentative type witnesses to be found across a protocol
hierarchy, eliminating some recursion through associated type
inference. Fixes a recent regression in validation-test/stdlib/CollectionTypes.swift, as well as rdar://problem/36453271.
2018-01-24 23:01:21 -08:00
Pavel Yaskevich
a11263b156 [ConstraintSystem] Bind Self to correct contextual type for nested types in protocol
If something that we are trying to contextually bind is a nested type inside
protocol or protocol extension, let's try to find the innermost conforming type
from the current declaration context and map Self parameter of the protocol
to that nominal type. Since nested types in protocols aren't yet implemented this
is going to result in failure, but that's better than crashing.

Resolves: rdar://problem/36449760
2018-01-24 18:21:26 -08:00
Michael Gottesman
13d19e5a23 %swift-target-frontend => %target-swift-frontend.
Looks like it was a typo.
2018-01-16 10:48:04 -08:00
Ben Cohen
ca6c6b1d36 [stdlib] Cleanup DefaultIndices, delete dead code (#13952)
* Remove a bunch of Default(Bidirectional|RandomAccess)Indices usage from stdlib and test

* Remove some DefaultRandomAccessIndices and IndexDistance usage from Foundation

* Remove no-longer-used internal type in Existentials.swift

* Get rid of indicesForTraversal
2018-01-15 13:48:08 -08:00
Slava Pestov
3717aa41cc Add regression test for https://bugs.swift.org/browse/SR-6730 2018-01-12 00:06:02 -08:00
Erik Eckstein
cd3d50a5d9 ABI: Change the mangling prefix from _T0 to $S 2018-01-06 13:55:59 -08:00
Doug Gregor
8b58b0dbb4 [Type checker] Make redeclaration checking validate fewer declarations.
Redeclaration checking was validating all declarations with the same
base name as the given declaration (and in the same general nominal
type), even when it was trivial to determine that the declarations
could not be conflicting. Separate out the easy structural checks
(based on kind, full name, instance vs. non-instance member, etc.) and
perform those first, before validation.

Fixes SR-6558, a case where redeclaration checking caused some
unnecessary recursion in the type checker.
2017-12-30 23:27:04 -08:00