Commit Graph

481 Commits

Author SHA1 Message Date
Rintaro Ishizaki
5217b68f08 [Parse] Set ErrorType to invalid ParamDecl
TypeChecker assumes invalid decl has valid type.

https://bugs.swift.org/browse/SR-8475
rdar://problem/43057057
2018-08-09 15:55:33 +09:00
Doug Gregor
3018becde7 [Type checker] Eliminate type checking from early extension binding.
Use ExtensionDecl::getExtendedNominal() to wire up extensions to their
nominal types early in type checking (the bindExtensions()) operation,
rather than going through type validation to do so.
2018-08-03 11:26:49 -07:00
Doug Gregor
bd5f5d80e4 [AST] Add ExtensionDecl::getExtendedNominal().
Introduce ExtensionDecl::getExtendedNominal() to provide the nominal
type declaration that the extension declaration extends. Move most
of the existing callers of the callers to getExtendedType() over to
getExtendedNominal(), because they don’t need the full type information.

ExtensionDecl::getExtendedNominal() is itself not very interesting yet,
because it depends on getExtendedType().
2018-08-03 11:26:48 -07:00
Mark Lacey
78d83e5703 Use %target-typecheck-verify-swift where possible. 2018-07-26 23:13:43 -07:00
Doug Gregor
b421d08955 [GSB] Use resolved type when looking for a representative constraint.
When looking for a representative superclass constraint, take into
account other same-type constraints by comparing against the resolved
superclass constraint type rather than the type as spelled.

Fixes SR-8179 / rdar://problem/41851224.
2018-07-26 12:42:29 -07:00
Ben Cohen
345879429b [stdlib] Take several underscored stdlib functions private (#18134)
* Make _sanityCheck internal

* Make _debugPrecondition internal

* Make Optional._unsafelyUnwrappedUnchecked internal.

* Make _precondition internal

* Switch Foundation _sanityChecks to assertions

* Update file check tests

* Remove one more _debugPrecondition

* Update Optimization-with-check tests
2018-07-24 18:26:19 -07:00
Doug Gregor
5c008ab2ce [Type checker] Don't substitute into unresolved types.
Unresolved types are formed in a few specific places within the type
checker's recovery path; don't let them bleed into the substitution
logic. Fixes rdar://problem/42448618.
2018-07-24 16:56:43 -07:00
Huon Wilson
7c088beadc Merge pull request #18057 from huonw/sr8240
[test] Stop a test relying on inconsistent formatting of an error message.
2018-07-19 13:24:20 +10:00
Huon Wilson
db04e817cc [test] Stop a test relying on inconsistent formatting of an error message.
Fixes rdar://problem/42351773.
2018-07-19 09:39:06 +10:00
Huon Wilson
c12bb46145 Merge pull request #18004 from huonw/sr8240
[AST] Member lookup in the GSB needs to understand equivalence classes with concrete types.
2018-07-18 12:46:08 +10:00
Slava Pestov
42a3ad3bf0 AST: Fix over-eager collapseSpecializedConformance()
It's possible that the conforming type is equal to the generic
conformance type, but some of the substitutions replace an
abstract conformance with a concrete one.

In this case we cannot collapse away the specialized conformance,
because we lose information that way.

Fixes <rdar://problem/40164371>.
2018-07-17 14:41:49 -07:00
Huon Wilson
ea1560f43b [AST] Member lookup in the GSB needs to understand equivalence classes with concrete types.
A constraint like `Parameter == SomethingConcrete` means references to
`Parameter` in that context behave like `SomethingConcrete`, including for name
resolution. Handling the parameter as just a parameter type means that it won't
find any non-protocol nested types (i.e. things other than associated types and
protocol typealiases are invisible).

Fixes rdar://problem/42136457 and SR-8240.
2018-07-17 22:54:22 +10:00
Slava Pestov
a78209610c Add test case for crasher that's already fixed on master 2018-07-04 00:42:33 -07:00
Slava Pestov
308463af38 Add test case for bug that's already fixed 2018-07-03 16:03:07 -07:00
Slava Pestov
28b0606b46 'Migrate' compiler crashers to Swift 4 2018-07-03 16:03:07 -07:00
Pavel Yaskevich
2ce5ae34c1 [Parser] Make sure to add implicit parens to call for prefix/postfix operators when needed
Currently when call involving prefix/postfix operator is formed we
don't wrap argument in implicit parens (like we do with other calls)
when user didn't provide any explicitly, this is bad because
argument-to-parameter matcher requires multiple special cases to handle
such behavior, so let's start wrapping arguments in implicit parens instead.

Resolves: rdar://problem/40722855
Resolves: [SR-7840](https://bugs.swift.org/browse/SR-7840)
2018-07-02 06:07:15 -07:00
Doug Gregor
932e9bef2f [Type checker] Look through optional injections when checking for rethrows.
Fixes SR-5427.
2018-06-29 09:35:01 -07:00
Anthony Latsis
092666526c Update fixed crasher validation test 2018-06-22 05:23:15 +03:00
Huon Wilson
92189c6079 Merge pull request #17356 from huonw/lazier-conditional-requirements
More errors instead of crashes for conditional conformances that are invalid or involve hard-to-resolve recursion
2018-06-21 11:59:49 +10:00
Huon Wilson
a21a7798d8 [Sema] Be more resilient about unavailable conditional requirements in error cases.
When we're trying to diagnose something, it's a bad look if we crash
instead. This changes the bad-associated-type recovery path to not require that
the conditional requirements have been computed, and instead detects that as a
possible error.

Fixes https://bugs.swift.org/browse/SR-8033.
2018-06-21 10:53:30 +10:00
Huon Wilson
10b30fef78 [GSB] Explicit error on unsupported conditional conformance recursion.
This doesn't fix the fundamental problem of correctly handling such cases, but
it is better than the "error message" that occurred previously:

    Assertion failed: ((bool)typeSig == (bool)extensionSig && "unexpected generic-ness mismatch on conformance").

Fixes the crash rdar://problem/41281406 (that in
https://bugs.swift.org/browse/SR-6569 (rdar://problem/36068136)),
https://bugs.swift.org/browse/SR-8019 (rdar://problem/41216423) and
https://bugs.swift.org/browse/SR-7989 (rdar://problem/41126254).
2018-06-21 10:53:30 +10:00
Slava Pestov
5d2752f7d2 Run tests with -swift-version 4 by default
Some test now fail, so add an explicit -swift-version 3.
2018-06-19 23:24:19 -07:00
Slava Pestov
e6c4a3825e Update a few tests to pass with -swift-version 4 2018-06-19 23:23:20 -07:00
Robert Widmann
0b33a69540 Merge pull request #17195 from brentdax/label-fable
Implicit tuple interpolations, take two
2018-06-18 15:54:30 -07:00
Pavel Yaskevich
969fb35f60 Merge pull request #17270 from xedin/rdar-41141944
[TypeChecker] When formatting witness type for diagnostics don't assu…
2018-06-16 01:21:35 -07:00
Pavel Yaskevich
235ed55004 [TypeChecker] When formatting witness type for diagnostics don't assume it's always valid
Sometimes witness candidates have error type e.g. when re-declaration checking
marks them as `invalid`, so formatting of the diagnostic
should account of potential witnesses not having a valid type.

Resolves: rdar://problem/41141944
2018-06-15 19:50:25 -07:00
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