Commit Graph

117 Commits

Author SHA1 Message Date
Hamish Knight
91222b9ebe [Completion] Avoid using unbound contextual type in argument completion
Match the logic in `getTypeForCompletion` and avoid using an unbound
generic type as the expected type for a completion.

rdar://155420395
2025-07-09 13:02:32 +01:00
Hamish Knight
9671ed9d85 [Completion] Map failable initializer result type into context
Make sure we don't pass an interface type to `setTypeContext`.

rdar://155038769
2025-07-04 13:59:07 +01:00
Hamish Knight
ee5f4df5ee Merge pull request #82775 from hamishknight/simple-fix-6.2
[6.2] [CS] Ensure type variables are eliminated by `Solution::simplifyType`
2025-07-04 10:56:34 +01:00
Hamish Knight
7e537b7f00 [CS] Ensure type variables are eliminated by Solution::simplifyType
`TypeSimplifier` may not eliminate type variables from e.g the
pattern types of pattern expansion types since they can remain
unresolved due to e.g having a placeholder count type. Make sure we
eliminate any remaining type variables along with the placeholders.
There's probably a more principled fix here, but this is a quick and
low risk fix we can hopefully take for 6.2.

rdar://154954995
2025-07-03 17:53:23 +01:00
Hamish Knight
4c6e06fed3 [AST] Use ErrorType for invalid value generic parameter
If we fail to resolve the value type for a value generic parameter,
previously we would have returned a null Type, causing crashes
downstream. Instead, return an ErrorType, leaving a null Type for
cases where the generic parameter isn't a value generic at all.

rdar://154856417
2025-07-02 21:19:45 +01:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Alex Hoppen
a5a17aa955 [tests] Add a %batch-code-completion lit substitution
I could never remember the command to run batch code completion tests. Add a lit substitution for it.
2023-09-18 13:57:49 -07:00
Alex Hoppen
00eaed3af9 [CodeCompletion] Migrate postfix expr completion to solver-based 2023-07-07 19:51:01 +02:00
Anthony Latsis
afb1eecb3e Gardening: Migrate test suite to GH issues: validation-test/IDE 2022-09-19 22:47:19 +03:00
Slava Pestov
7d8f3e6b63 AST: Change return type of Requirement::subst() to Requirement
Instead of returning None, let callers check hasError() if they need to.

Fixes rdar://problem/98565072.
2022-08-12 14:03:57 -04:00
Alex Hoppen
5d01a097e1 [CodeCompletion] Don't distinguish convertible and idenical type relation
I think that preferring identical over convertible makes sense in e.g. C++ where we have implicit user-defined type conversions but since we don’t have them in Swift, I think the distinction doesn’t make too much sense, because if we have a `func foo(x: Int?)`, want don’t really want to  prioritize variables of type `Int?` over `Int` Similarly if we have `func foo(x: View)`, we don’t want to prioritize a variable of type `View` over e.g. `Text`.

rdar://91349364
2022-04-13 08:28:17 +02:00
Alex Hoppen
f42f961faf [Sema] Copy key path component types when merging solutions
In 2eeff365b1 I forgot to copy key path component types when applying a solution to the constraint system. That caused a crash in key path code completion.

Fixes rdar://81118700 [SR-14979]
2021-07-30 11:07:21 +02:00
Rintaro Ishizaki
75a0c9f819 [CodeCompletion] Add 'IsSystem' flag to code completion result item
'key.is_system: 1' is added if the associated declaration is from a
system module.

rdar://problem/62617558
2020-05-11 12:24:36 -07:00
Argyrios Kyrtzidis
bbdada475b [Parse] Try to preserve the invariant that anything that contains KeyPathDotExpr must be wrapped in KeyPathExpr
Even in the presence of invalid code. Fixes typechecker crash in rdar://50666427
2020-02-20 15:07:00 -08:00
Slava Pestov
1d2d653844 IDE: Redo typeCheckContext()
- Don't type check top-level contexts multiple times
- Use validateDecl() instead of typeCheckDecl() when possible
2018-06-30 00:20:37 -07:00
Slava Pestov
e58ae766a3 Fix and un-XFAIL regressed crashers from recent stdlib change 2017-05-17 05:51:51 -07:00
Maxim Moiseev
1c1b2b966d [stdlib] String : RangeReplaceableCollection & BidirectionalCollection (#8921)
* [stdlib] String : RangeReplaceableCollection & BidirectionalCollection

* Add source compatibility hack for Swift.max

* Add source compatibility hack for Swift.min

* Remove redundant conformance in benchmarks

* Fix stupid typo I thought I'd already pushed

* XFAIL testing now-redundant conformance

* XFAIL an IDE test for now
2017-04-23 20:04:54 -07:00
Slava Pestov
e063e8297c Sema: Some fixes for the ITC
- In functions called from resolveType(), consistently
  use a Type() return value to indicate 'unsatisfied
  dependency', and ErrorType to indicate failure.

- Plumb the unsatisfiedDependency callback through the
  resolution of the arguments of BoundGenericTypes, and
  also pass down the options.

- Before doing a conformance check on the argument of a
  BoundGenericType, kick off a TypeCheckSuperclass request
  if the type in question is a class. This ensures we don't
  recurse through NominalTypeDecl::prepareConformanceTable(),
  which wants to see a class with a valid superclass.

- The ResolveTypeOfDecl request was assuming that
  the request was satisfied after calling validateDecl().
  This is not the case when the ITC is invoked from a
  recursive call to validateDecl(), hack this up by returning
  *true* from isResolveTypeDeclSatisfied(); otherwise we
  assert in satisfy(), and we can't make forward progress
  in this case anyway.

- Fix a bug in cycle breaking; it seems if we don't invoke
  the cycle break callback on all pending requests, we end
  up looping forever in an outer call to satisfy().

- Remove unused TR_GlobalTypeAlias option.
2016-12-09 17:36:49 -08:00
Xi Ge
6bbdf4a837 [Mangler] Check the order of generic type parameters before mangling them to avoid assertion hit. 2016-12-09 09:51:40 -08:00
Jordan Rose
49e6c06eef [validation-test] Remove "REQUIRES: asserts" from /fixed/ crash cases. (#6156) 2016-12-08 19:06:32 -08:00
Xi Ge
54e8527d5c [code-completion] Ensure consumeDecl() does not alter the state of parser. (#6110)
This also fixes IDE/crashers/029-swift-decl-walk.swift.
2016-12-06 16:01:29 -08:00
Ben Langmuir
ef7f8f7c9a Merge pull request #6102 from benlangmuir/fix-032
[code-completion] Allow ErrorType in solution to avoid assertion failure
2016-12-06 12:26:33 -08:00
Ben Langmuir
49f144205f Merge pull request #6085 from nathawes/rdar28867801
[code-completion] Fix crash in printParameterList when paramListTy is…
2016-12-06 11:46:26 -08:00
Ben Langmuir
c01bff7ddb [code-completion] Allow ErrorType in solution to avoid assertion failure
When CSGen encounters an error it may set a type to ErrorType, but the
system will still "solve".
2016-12-06 10:42:16 -08:00
Slava Pestov
dbdb8d62ea Merge pull request #6094 from slavapestov/cleanup-generic-resolver-workaround
Cleanup generic resolver workaround
2016-12-06 10:24:18 -08:00
Slava Pestov
fdaa886065 Sema: Rework resolveTypeInContext()
Separate the "find the correct context" part from "substitute in the
base type" part. The former can go away completely after a bit of
refactoring.
2016-12-06 09:39:28 -08:00
swift-ci
20c44e6de4 Merge pull request #6095 from akyrtzi/fix-ide-crash-103 2016-12-06 09:06:31 -08:00
Argyrios Kyrtzidis
7a390e1fac [code-completion] Improve robustness of Solution::computeSubstitutions and check if OpenedTypes contains the provided locator.
Fixes validation-test/IDE/crashers/103-swift-constraints-solution-resolvelocatortodecl.swift.
2016-12-06 08:28:53 -08:00
Xi Ge
1f7a5f4412 Fixing /IDE/crashers/016-swift-mangle-mangler-mangleidentifier.swift (#6079) 2016-12-05 21:20:35 -08:00
Xi Ge
1570f8e4f1 Fixing IDE/crashers/091-swift-typechecker-computedefaultaccessibility.swift (#6084) 2016-12-05 20:52:07 -08:00
swift-ci
e0bec70809 Merge pull request #6090 from bitjammer/guard-null-generic-env 2016-12-05 19:59:12 -08:00
David Farler
25e623addb Don't resolve a generic type parameter type from null environments
The generic environment of a GenericTypeToArchetypeResolver may be
`nullptr`, as returned by DeclContext::getGenericEnvironmentOfContext,
during prechecking of closure expressions at the necessarily non-generic
top level.

Fixes a couple of crashers.
2016-12-05 19:34:02 -08:00
swift-ci
5b822979a1 Merge pull request #6088 from bitjammer/correct-utf-8-illegal-octets 2016-12-05 17:51:10 -08:00
swift-ci
de858041e7 Merge pull request #6087 from akyrtzi/fix-ide-crash-084 2016-12-05 17:51:09 -08:00
David Farler
330c2d96e6 Make the lexer UTF-8 RFC 3629 correct re: prefix octets
RFC 2279 states that, in UTF-8:
"The octet values FE and FF never appear."

RFC 3629 states that, in UTF-8:
"The octet values C0, C1, F5 to FF never appear."

Generalize the check to advance past invalid starting bytes for
a UTF-8 sequence to fix a crash in the lexer.
2016-12-05 17:21:17 -08:00
Argyrios Kyrtzidis
fc678740db [code-completion] Avoid a tentantive parse when in code-completion mode and make sure CodeCompletionExpr has a token range.
The tentantive parse is used for diagnostic purposes but can cause code-completion to delay the same decl twice.
The range of CodeCompletionExpr was previously character range which invalidated invariants of the AST.

Fixes:
	validation-test/IDE/crashers_fixed/084-swift-parser-consumedecl.swift
	validation-test/IDE/crashers_fixed/104-swift-gettypeofcompletioncontextexpr.swift
2016-12-05 17:09:49 -08:00
Nathan Hawes
528f38aadb [code-completion] Fix crash in printParameterList when paramListTy is Error type rdar://problem/28867801 2016-12-05 15:16:13 -08:00
Argyrios Kyrtzidis
b0705b455a [code-completion] Fix assertion hit when calling 'DeclContext::getResilienceExpansion()' with invalid code
Fixes:
	validation-test/IDE/crashers/074-swift-valuedecl-geteffectiveaccess.swift
	validation-test/IDE/crashers/095-swift-declcontext-getresilienceexpansion.swift
2016-12-05 14:39:53 -08:00
swift-ci
796994cd80 Merge pull request #6080 from akyrtzi/fix-crash-014 2016-12-05 13:30:31 -08:00
Argyrios Kyrtzidis
f548c2ba52 [code-completion] Fix assertion hit when completing after incomplete property.
Make sure to call getPtrOrNull() instead of get() directly.
2016-12-05 12:48:48 -08:00
swift-ci
159a1d93a2 Merge pull request #6077 from nkcsgexi/ide-crash-012 2016-12-05 12:29:03 -08:00
swift-ci
c14391de1f Merge pull request #6076 from benlangmuir/fix-040 2016-12-05 12:16:08 -08:00
Xi Ge
5699b5a1e0 Fixing /IDE/crashers/012-swift-mangle-mangler-manglecontext.swift 2016-12-05 11:55:21 -08:00
Ben Langmuir
1ca799bfda [code-completion] Fix crash in typeCheckConstructorBodyUntil with null nominal context
With erroneous code, such as in code-completion, it's not safe to assume
that the constructor is inside a nominal decl context.

rdar://problem/28867794
2016-12-05 11:52:18 -08:00
Ben Langmuir
9894eeda45 [code-completion] Fix crash with missing func body in type-checking
We already fail early on a missing body in normal type-checking, but we
missed the case where we call typeCheckAbstractFunctionBodyUntil
directly, as in code-completion.

rdar://problem/28822204
2016-12-05 10:42:56 -08:00
Doug Gregor
46e6a38e50 Mark three crashers as resolved 2016-12-01 15:25:43 -08:00
Slava Pestov
7b59e75d34 IDE: hasType() => hasInterfaceType() 2016-11-29 03:05:31 -07:00
Slava Pestov
044034cae5 Sema: hasType() => hasInterfaceType() 2016-11-29 03:05:31 -07:00
Slava Pestov
6cbb494ad2 AST: Give all ValueDecls an interface type
Previously, getInterfaceType() would return getType() if no
interface type was set. Instead, always set an interface type
explicitly.

Eventually we want to remove getType() altogether, and this
brings us one step closer to this goal.

Note that ParamDecls are excempt from this treatment, because
they don't have a proper interface type yet. Cleaning this up
requires more effort.
2016-11-29 03:05:25 -07:00
Slava Pestov
ea28765ced Sema: Resolve invalid generic parameters to error types
When a generic parameter list fails to parse, we don't call
DeclContext::setGenericParams(), even though the generic
parameters are still available for name lookup.

This causes various crashes, which this patch fixes by
mapping the generic parameters to ErrorTypes.
2016-11-26 01:31:59 -05:00